1778 Posts in 581 Topics by 555 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 408 Views |
-
[User Error] Uncaught Exception: ManyManyList::add() can't be called until a foreign ID is set

1 June 2012 at 4:40pm Last edited: 1 June 2012 4:41pm
Hi,
in my form, I tried to add new record with many-many relations using checkboxsetfield, but it returned the error "[User Error] Uncaught Exception: ManyManyList::add() can't be called until a foreign ID is set".
Anyone know what does it mean and how do I solve it?
By the way, I m using SS3 beta 3.
Many thanks.
-
Re: [User Error] Uncaught Exception: ManyManyList::add() can't be called until a foreign ID is set

1 June 2012 at 5:49pm Last edited: 1 June 2012 6:03pm
I have found a way to solve it - that is to write once before save and rewrite. But I don't feel like this is the proper way to do it, can anyone advise me on this? Thanks.
....
$Event = new Event();
if ($EventID == 0) {
$Event->write(); //write the event once before save would solve the problem
} else {
$Event->ID = $EventID;
}$form->saveInto($Event);
$Event->write();
... -
Re: [User Error] Uncaught Exception: ManyManyList::add() can't be called until a foreign ID is set

29 September 2012 at 5:55am
tfliam,
Can you share where you would have the code?
Thanks
-
Re: [User Error] Uncaught Exception: ManyManyList::add() can't be called until a foreign ID is set

30 September 2012 at 5:50pm Last edited: 30 September 2012 5:51pm
The code is at the Page controller where you add your object, you may check out the structure of the codes in silverstripe tutorial http://doc.silverstripe.org/framework/en/tutorials/3-forms, my codes is as shown below:
class EventAddPage_Controller extends Page_Controller
{
...
public function doFrontEndForm($data, $form)
{$Event = new Event();
$Event->write(); //for adding new record, it will have error when it comes to many-many relations if without write once before save
$form->saveInto($Event);
$Event->write();
}
...
}
| 408 Views | ||
|
Page:
1
|
Go to Top |


