Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » "extends Member" and only error's

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2174 Views
  • UnrealMinds
    Avatar
    Community Member
    8 Posts

    "extends Member" and only error's Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: "extends Member" and only error's Link to this post

    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

  • UnrealMinds
    Avatar
    Community Member
    8 Posts

    Re: "extends Member" and only error's Link to this post

    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

    2174 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.