Jump to:

22989 Posts in 11842 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » [Solved] Member decorator and has_one

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 153 Views
  • theade
    Avatar
    Community Member
    9 Posts

    [Solved] Member decorator and has_one Link to this post

    Hello, quick question hopefully.

    I'm decorating Member, adding some DB fields and a has_one relationship. Problem is that the has_one relationship is only available on one side.

    class SomeDataObject extends DataObject {
       static $db = array(
          'Title' => 'Text'
       );

       static $has_one = array(
          'Member' => 'Member'      
       );
       
    }

    and

    class CustomMember extends DataExtension {

       static $has_one = array(
          'SomeDataObject' => 'SomeDataObject'
       );   
       
    }

    I'm using model admin for SomeDataObject and can add Members to SomeDataObjects. But when I look at the member in the security area, the field for SomeDataObject is empty and in the DB the SomeDataObjectID field in Member is 0.

    What am I doing wrong?

    Thanks

  • martimiz
    Avatar
    Forum Moderator
    1038 Posts

    Re: [Solved] Member decorator and has_one Link to this post

    Edit: removed obviously wrong answer.

  • theade
    Avatar
    Community Member
    9 Posts

    Re: [Solved] Member decorator and has_one Link to this post

    Really, no one-to-one relationships? Seems a bit strange, but OK, thanks, that's good to know.

  • martimiz
    Avatar
    Forum Moderator
    1038 Posts

    Re: [Solved] Member decorator and has_one Link to this post

    Ok... And i'm obviously stupid today Sorry, please ignore what I just said about the one_to_one relation!!!

    http://doc.silverstripe.com/framework/en/topics/datamodel#has-one
    http://doc.silverstripe.com/framework/en/topics/datamodel#belongs-to

    Two has_ones will create two foreign keys, one on each Object class, but SilverStripe will see them as two separate relations, Updating one will not automatically update the other. Belongs_to will tell SilverStripe to look for a relationship ID on the other side...

  • theade
    Avatar
    Community Member
    9 Posts

    Re: [Solved] Member decorator and has_one Link to this post

    Cool. That's fixed it. Cheers for your help

    153 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.