5521 Posts in 1733 Topics by 1220 members
|Go to End|
29 April 2009 at 5:52pm
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?
29 April 2009 at 11:51pm
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
|Go to Top|