21496 Posts in 5784 Topics by 2622 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 288 Views |
-
has_one relationship database error

17 January 2012 at 2:27pm Last edited: 17 January 2012 2:34pm
Hello
Using SS 3.0.0-alpha-1 I am trying to link a page with its author:
class AuthorPage extends Page {
public static $has_one = array (
'Author' => 'Member'
);
protected function onBeforeWrite () {
$this->Author = Member::currentUser ();
parent::onBeforeWrite ();
}
}When I add an AuthorPage in the CMS with the "add new" dialogue, I get the following error message:
---
[User Error] Couldn't run query: INSERT INTO "AuthorPage" ("ID") VALUES (17) Cannot add or update a child row: a foreign key constraint fails ("silverstripe"."authorpage", CONSTRAINT "authorpage_ibfk_1" FOREIGN KEY ("AuthorID") REFERENCES "Member" ("ID"))
POST /admin/pages/AddFormLine 562 in /Users/georg/silverstripe/sapphire/model/MySQLDatabase.php
---The error message is the same if the onBeforeWrite () function is missing in AuthorPage.
What am I doing wrong here?
Thanks for your hints.gh
-
Re: has_one relationship database error

20 January 2012 at 7:35pm
Does anyone know how this is supposed to work?
Is there a bug in SS3.0.0-alpha1, or am I not doing it right?TIA,
gh
-
Re: has_one relationship database error

20 January 2012 at 10:29pm
Should be...
protected function onBeforeWrite () {
$this->AuthorID = Member::currentUserID();
parent::onBeforeWrite ();
} -
Re: has_one relationship database error

21 January 2012 at 9:16pm
Great, that works!
Thank you very much!gh
| 288 Views | ||
|
Page:
1
|
Go to Top |


