3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1334 Views |
-
saving a has_one relation

6 January 2011 at 10:45pm
Hi!
I am wondering if this is the way to save my has_one relation.
It works, but it's not a nice way.$Website = new Website();
$form->saveInto($Website);
$Website->MaintainerID = $Member->ID;
$Website->write(); -
Re: saving a has_one relation

7 January 2011 at 1:37pm
I'm curious too - I've used $dataobject->setComponent('Maintainer',$Member->ID) I think, but more often for has_many / many_many - but I normally do it like you have posted...
-
Re: saving a has_one relation

10 January 2011 at 4:06am
What's wrong with saving the has_ones in that way?
-
Re: saving a has_one relation

10 January 2011 at 9:53pm
There's nothing wrong with it. It works ok, but I was wondering if there is a better/ nicer way to do:
$Website->MaintainerID = $Member->ID;
A way in which you don't have to involve the ID. Is there a method in the data object which couples and saves these has_one relations for you?
-
Re: saving a has_one relation

13 January 2011 at 1:33am
At least a DropdownField in the CMS would work in situations where you 'd want to choose from (a limited amount of) available 'has_ones'...
-
Re: saving a has_one relation

18 January 2011 at 6:21am
yep that's true. I'm saving Member->ID so checking if Member object exists before saving should also do the trick.
Guess we'll have to stick to this way of saving the relation. -
Re: saving a has_one relation

25 February 2011 at 2:54am
It would be great if a future ss version could support something like the following:
$Website->Maintainer = $Member;
For now I use the following as a work-around:
$Website->Maintainer = $Member;
$Member->Websites()->add($Website);but this hack doesn't work of course if you have just one-way many to one (unidirectional).
best regards
andi -
Re: saving a has_one relation

25 February 2011 at 5:06pm
bcc2k any feature requests should go to open.silverstripe.org. I think having it behave like that would be a practical feature. Not sure of the implications or why it doesn't do it currently.
| 1334 Views | ||
|
Page:
1
|
Go to Top |





