Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » $has_one vs $db

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

Page: 1
Go to End
Author Topic: 1979 Views
  • DanStephenson
    Avatar
    Community Member
    115 Posts

    $has_one vs $db Link to this post

    When I am adding new fields to the CMS using my Page.php file, how do I know which fields should go in the $has_one array vs which ones go in the $db array?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: $has_one vs $db Link to this post

    Hi Dan

    THe $db array is for single fields that are are stored in a column on the current pages database table. So for example the pages title is stored in the 'Title' column on the SiteTree table.

    The has_one array is for attaching other DataObjects to the current page in a 'Has one' relationship. So for example when you add a an image to the has_one array, it adds an ImageID column to the Page's table. This ImageID is then used to retrieve that actual image object and all it's columns from the File table.

    So think of it like this; If you are just adding a single piece of data to a page (a bit of text, a number etc) use the $db. But if you want to attach another DataObject that has it's own table (an Image, File or AnotherPage etc.) then you add it to the has_one array.

    Hope that helps

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