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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Reference to relation entity from controller


Go to End


3 Posts   1448 Views

Avatar
Trym

Community Member, 18 Posts

21 November 2008 at 11:14pm

Edited: 21/11/2008 11:15pm

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

Avatar
ajshort

Community Member, 244 Posts

23 November 2008 at 8:42am

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.

Avatar
Trym

Community Member, 18 Posts

24 November 2008 at 8:36pm

Edited: 24/11/2008 8:37pm

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