This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » Admin generator problem
Admin generator problem [message #102590] Fri, 16 July 2010 13:52 Go to next message
skrobek  is currently offline skrobek
Messages: 1
Registered: July 2010
Location: Poland
Junior Member
Hello,
I have a problem with admin generator.
I have Table Content:
content:
    _attributes: { phpName: Content }
    id: ~   
    content_type_id: { phpName: ContentTypeId, type: INTEGER, size: '11', required: true, foreignTable: content_type, foreignReference: id, onDelete: RESTRICT, onUpdate: RESTRICT }
    title: { phpName: Title, type: VARCHAR, size: '255', required: false }    
    author: { phpName: Author, type: INTEGER, size: '11', primaryKey: true, required: true, foreignTable: sf_guard_user, foreignReference: id, onDelete: RESTRICT }
   
column author

Where author is foregin key to user Id i sf_guard_user table.
In Form this this is a hiddeninput field. When i try to add a new content, i have error:
39	Error sfPropelLogger	SQLSTATE[HY000]: General error: 1452 Cannot add or update a child row: a foreign key constraint fails (`wspanialespa4/content`, CONSTRAINT `content_FK_3` FOREIGN KEY (`author`) REFERENCES `sf_guard_user` (`id`))
40	Error PropelException	Unable to execute INSERT statement. [wrapped: SQLSTATE[HY000]: General error: 1452 Cannot add or update a child row: a foreign key constraint fails (`wspanialespa4/content`, CONSTRAINT `content_FK_3` FOREIGN KEY (`author`) REFERENCES `sf_guard_user` (`id`))] 


Where i can set a value of current user id ?
In generator ? How ?
Or maybe somewhere else ?

P.S sorry for my eng.
Re: Admin generator problem [message #102616 is a reply to message #102590 ] Fri, 16 July 2010 16:02 Go to previous message
sescandell  is currently offline sescandell
Messages: 65
Registered: December 2008
Location: France
Member
Hi,

Quote:

In Form this this is a hiddeninput field

Which field ?
If you mean the author field, so your error is normal.

In your schema, you declare author column as a primaryKey and as required.
That means, in order to add a content entry, you NEED to specify an author (so you cannot hide the field). Or if you hide it, you have, before saving your content, to assign a value to this one.

Here is an example (which just represents the logic, it cannot work like that)

public function executeMyAction(sfWebrequest $request)
{
    $this->form = new ContentForm();
    
    if($request->isMethod('post'))
    {
      $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
      if($this->form->isValid())
      {
        $content = $this->form->getObject();
        $content->setAuthor($this->getUser()->getId());
        $content->save();
        ...
      }
    }
    ...
}

[Updated on: Fri, 16 July 2010 16:05]

Previous Topic:upgrading from 1.2 to 1.4
Next Topic:How to create a new form
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software