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