3070 Posts in 869 Topics by 651 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 801 Views |
-
In the case of a 'has-many' relation, do I have to declare the "has-one" relation and what if I don't ?

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'
);
}and
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.
Thanks,
Lise -
Re: In the case of a 'has-many' relation, do I have to declare the "has-one" relation and what if I don't ?

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.
-
Re: In the case of a 'has-many' relation, do I have to declare the "has-one" relation and what if I don't ?

3 April 2010 at 4:31pm
Hamish,
Thank you for your reply ...you 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
| 801 Views | ||
|
Page:
1
|
Go to Top |


