Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

"extends Member" and only error's


Reply

3 Posts   2203 Views

Avatar
UnrealMinds

27 July 2009 at 5:15am (Last edited: 27 July 2009 5:18am), Community Member, 8 Posts

Hi there,

I have made this class (/mysite/code/userextras.php):

<?php
class Userextras extends Member {
   static $db = array(
    'Adress' => 'Text',
    'Age' => 'Text',
   );   
}
?>

but when I made a "/dev/build" I only get the following response at the browser:

Website Error
There has been an error

The website server has not been able to respond to your request.

and via eMail the following error-message:

Error: Couldn't run query: SELECT `Member`.*, `Userextras`.*, `Member`.ID, if(`Member`.ClassName,`Member`.ClassName,'Member') AS RecordClassName FROM `Member` LEFT JOIN `Userextras` ON `Userextras`.ID = `Member`.ID WHERE (Member.ID = 1) ORDER BY Surname, FirstName LIMIT 1 Table 'test.userextras' doesn't exist
At line 400 in /sapphire/core/model/MySQLDatabase.php

Couldn't run query: SELECT `Member`.*, `Userextras`.*, `Member`.ID, if(`Member`.ClassName,`Member`.ClassName,'Member') AS RecordClassName FROM `Member` LEFT JOIN `Userextras` ON `Userextras`.ID = `Member`.ID WHERE (Member.ID = 1) ORDER BY Surname, FirstName LIMIT 1 Table 'test.userextras' doesn't exist
Line 400 of MySQLDatabase.php
MySQLDatabase->databaseError(Couldn't run query: SELECT `Member`.*, `Userextras`.*, `Member`.ID, if(`Member`.ClassName,`Member`.ClassName,'Member') AS RecordClassName FROM `Member` LEFT JOIN `Userextras` ON `Userextras`.ID = `Member`.ID WHERE (Member.ID = 1) ORDER BY Surname, FirstName LIMIT 1 | Table 'test.userextras' doesn't exist,256)
Line 102 of MySQLDatabase.php
MySQLDatabase->query(SELECT `Member`.*, `Userextras`.*, `Member`.ID, if(`Member`.ClassName,`Member`.ClassName,'Member') AS RecordClassName FROM `Member` LEFT JOIN `Userextras` ON `Userextras`.ID = `Member`.ID WHERE (Member.ID = 1) ORDER BY Surname, FirstName LIMIT 1,256)
Line 120 of DB.php
DB::query(SELECT `Member`.*, `Userextras`.*, `Member`.ID, if(`Member`.ClassName,`Member`.ClassName,'Member') AS RecordClassName FROM `Member` LEFT JOIN `Userextras` ON `Userextras`.ID = `Member`.ID WHERE (Member.ID = 1) ORDER BY Surname, FirstName LIMIT 1)
Line 426 of SQLQuery.php
SQLQuery->execute()
Line 2524 of DataObject.php
DataObject->instance_get_one(Member.ID = 1,)
Line 2461 of DataObject.php
DataObject::get_one(Member,Member.ID = 1)
Line 422 of Member.php
Member::currentUser()
Line 104 of Permission.php
Permission::check(ADMIN)
Line 27 of DevelopmentAdmin.php
DevelopmentAdmin->init()
Line 113 of Controller.php
Controller->handleRequest(HTTPRequest)
Line 277 of Director.php
Director::handleRequest(HTTPRequest,Session)
Line 121 of Director.php
Director::direct(/dev/build)
Line 118 of main.php

The Database wasn't build. Do I make other extends for example to a DataObject, everything works fine.

I don't know what to do by now? - Can anybody help?
I am using SilverStripe at version 2.3.2 and the DailyBuilds at a Mac with ZendServer 4.0.4.

I am working through the german SilverStripe-book and was now blocked at side 212 with this error.

Avatar
Willr

27 July 2009 at 4:51pm Forum Moderator, 5511 Posts

try change your $db to

static $db = array(
'Adress' => 'Text',
'Age' => 'Text'
);

Then rerun dev/build.

Note that when editing member object sometimes rather then subclassing them (by using extends Member) decorating them with a DataObjectDecorator is a better solution

Avatar
UnrealMinds

27 July 2009 at 9:17pm (Last edited: 27 July 2009 9:18pm), Community Member, 8 Posts

thanx willr - the part with extending the Member-class doesn't work, but with a DataObjectDecorator it works, for the first part. ;-)

Now I have in "/mysite/code/Developer.php":

class Developer extends DataObjectDecorator {
   function extraStatics() {
    return array(
    'db' => array(
    'Introduction' => 'Text',
    'Region' => 'Varchar(200)'
    ),
    'has_many' => array(
    'References' => 'Reference'
    ),
    'many_many' => array(
    'Skills' => 'Skill'
    )
    );
   }
}

and have extended the "mysite/_config.php" with the following line:

Object::add_extension('Member', 'Developer');

After run "/dev/build" I got no errors. But in the book the next step wil be to make a new extending ModelAdmin as showing here:

class CommunityAdmin extends ModelAdmin {
   public static $managed_models = array(
    'Developer',
    'Reference',
    'Skill',
   );
   static $url_segment = 'community';
}

And now I get via eMail the following error-message:

Error: Uncaught Exception: Object->__call(): the method 'getdefaultsearchcontext' does not exist on 'Developer'
At line 515 in /sapphire/core/Object.php