Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Reference to relation entity from controller

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1050 Views
  • Trym
    Avatar
    Community Member
    18 Posts

    Reference to relation entity from controller Link to this post

    Hi,

    I have at Page class with a

    static $many_many = array('Teasers' => 'TeaserPage');


    and would like to get a reference to the related Teasers from a function in the controller class (Page_Controller).

    Any suggestions are welcome.
    Thanks.

    Regards Trym

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Reference to relation entity from controller Link to this post

    Hi Trym,

    You can just do $this->Teasers() - as this will fall over to the data model your controller is attached to. The general rule is that you access DB fields like instance properties, and relationships like methods.

  • Trym
    Avatar
    Community Member
    18 Posts

    Re: Reference to relation entity from controller Link to this post

    Hi

    Thanks ajshort.
    What should I do if I needed only a few of the entities before extracting them from the database (e.g. sql: WHERE teasers.colour = 'blue')?
    And any hints where I can read about this (code, wiki, documentation)?

    Thanks.

    Regards Trym

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