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.

Customising the CMS /

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

$has_one vs $db

Go to End

2 Posts   2511 Views


Community Member, 116 Posts

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?

Carbon Crayon

Community Member, 598 Posts

29 April 2009 at 11:51pm

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