Jump to:

2580 Posts in 695 Topics by 540 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Creating has_many relation with self

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba

Page: 1
Go to End
Author Topic: 1409 Views
  • zenmonkey
    Avatar
    Community Member
    410 Posts

    Creating has_many relation with self Link to this post

    Can a dataobject have a has_many relation with self. I'm trying to set up a list of definitions, then include related terms. So each term would have to have a has_many relation with other terms.

  • Willr
    Avatar
    Forum Moderator
    4724 Posts

    Re: Creating has_many relation with self Link to this post

    I think you would need a many_many relationship for that as a Definition would have many Related Terms and each of those Related terms would probably have multiple definition it relates to.

    You can try add a many_many / belongs_many_many to the object and try it out. I think it *should* be fine with a many_many relationship on itself. Try it out and see what happens

  • MichaelCole
    Avatar
    Community Member
    2 Posts

    Re: Creating has_many relation with self Link to this post

    From IRC:

    michaelcole: Hello!
    michaelcole: I'm just checking out Silverstripe. How could I model a "has many reference to self" relationship with the ORM?
    simon_w: static $has_many = array ('LotsOfMe'=>__CLASS__); static $has_one = array('OneOfMe' => __CLASS__);
    michaelcole: Cool! Sounds simple. I like it!

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