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.

Data Model Questions /

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

In the case of a 'has-many' relation, do I have to declare the "has-one" relation and what if I don't ?

Go to End

3 Posts   1216 Views


Community Member, 47 Posts

3 April 2010 at 3:23pm

It would be a bit complex to explain why I want to do that but basically I am wondering if I can define something like :

class customers extends page

static $has_many = array(
'country' => 'country'


class country extends DataObject
static $db = array(
'CountryName' => 'Text',

Note that I did *NOT* define the has-one relation in 'country'.

I know that by omitting the reverse "has-one" relation I can not point to a list of customers linked to the same country but
I know I will never need to .

So my question is : am I breaking the data model by doing this ? What risk am I taking here?

I tried and it works ...I just want to make sure I am not overlooking something critical.

Any advice and comments would be appreciated.



Community Member, 712 Posts

3 April 2010 at 4:25pm

I'm a bit surprised that it still works - the has_one relation is really the important one in a one-many relation (it defines the other object id field in the database). Usually you can do without the has_many, but need the has_one, but in your case you should need both.

I would recommend you set it up correctly. The risk is that you've created the database field in a previous build, but removed the definition, so it might fail if you tried to rebuild from a fresh database.


Community Member, 47 Posts

3 April 2010 at 4:31pm


Thank you for your reply are probably very right because I am now experiencing s problem which, I suspect, is due to
the way I (incorrectly) define the relation. I will follow your advice.

Thanks again