[symfony-users] Re: Foreign key violation when saving embedded forms

2009-06-30 Thread Java geek

Yes, that was the problem, I need to create new User object and manually 
link to Registration.
I have already solved the problem, here's the solution.
http://solveme.wordpress.com/2009/06/30/foreign-key-violation-when-saving-symfony-embedded-forms/

Thanks
SN
- Original Message - 
From: "Campezzi" 
To: "symfony users" 
Sent: Tuesday, June 30, 2009 11:54 PM
Subject: [symfony-users] Re: Foreign key violation when saving embedded 
forms



Hi there!

I don't know if this applies to 1:1 relationships, but I had a similar
problem when trying to embed a for on a 1:n (an Author has many Books)
relationship and found the solution on this TRAC entry:

http://trac.symfony-project.org/ticket/4906

Towards the end of the discussion, jwage points this solution (it's
Doctrine, btw, but I don't think that is too relevant here):

# This is for a blank new book at the form
$Book = new Book();
$Book['author_id'] = $this->object['id'];
$bookForm = new BookForm($Book);
unset($bookForm['author_id']);
$form->embedForm('new', $bookForm);

So you see, you have to create a Book object first and "manually" link
it to the Author object. I think Doctrine handles 1:1 relationships
automatically, but Propel may not. I'm not sure about that. But I
guess if you take the manual approach from the example above, you may
have a good starting point :)

Also be sure to read through some of the messages posted to that TRAC
discussion, they really helped me grasp the concept of embedded forms
a bit better! ;)

Regards,

Thiago Campezzi



On Jun 29, 7:12 am, "Java geek"  wrote:
> Sorry, there was a typo...
>
> Here's the code.
>
> Schema
> propel:
>
> user:
> id: ~
> name: {type: varchar(100)}
>
> registrations:
> id: ~
> user_id: {type: integer, foreignTable: user, foreignReference: id, 
> required: true}
>
> RegistrationForm
>
> class RegistrationsForm extends BaseRegistrationsForm
> {
> public function configure()
> {
> unset($this['user_id']);
> $userform = new UserForm($this->object->getUser());
> $this->embedForm("User", $userform);
> }
>
> }
>
> UserForm
> class UserForm extends BaseUserForm
> {
> public function configure()
> {
> }
>
> }
>
> If I don't use required = true in required: true, in that case.. user is 
> saved in db.. but still user_id is null in registration, so no association 
> is made, user_id is not getting set.
>
> - Original Message -
> From: Java geek
> To: symfony-users@googlegroups.com
> Sent: Monday, June 29, 2009 3:27 PM
> Subject: [symfony-users] Re: Foreign key violation when saving embedded 
> forms
>
> I am using Symfony 1.2 and propel...
> - Original Message -
> From: Java geek
> To: symfony-users@googlegroups.com
> Sent: Monday, June 29, 2009 2:30 PM
> Subject: [symfony-users] Foreign key violation when saving embedded forms
>
> I have following schema.
>
> User
> id: ~
> name: {type: varchar(100)}
>
> Registrations
> id: ~
> user_id: {type: integer, foreignTable: User, foreignReference: id}
>
> schema is not complete, It shows important fields only.
>
> RegistrationForm
>
> unset($this['user_id']);
> $userform = new UserForm($this->object->getUser());
> $this->embedForm($userform);
>
> Form is displayed.. and it works when updating existing registrations.
>
> But it throws foreign key constraint violation when creating new 
> registrations. because user_id is null. Some how new user is not being set 
> on registration.
>
> What am I doing wrong?
>
> SN
> http://www.jsptube.com


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: Foreign key violation when saving embedded forms

2009-06-30 Thread Campezzi

Hi there!

I don't know if this applies to 1:1 relationships, but I had a similar
problem when trying to embed a for on a 1:n (an Author has many Books)
relationship and found the solution on this TRAC entry:

http://trac.symfony-project.org/ticket/4906

Towards the end of the discussion, jwage points this solution (it's
Doctrine, btw, but I don't think that is too relevant here):

# This is for a blank new book at the form
$Book = new Book();
$Book['author_id'] = $this->object['id'];
$bookForm = new BookForm($Book);
unset($bookForm['author_id']);
$form->embedForm('new', $bookForm);

So you see, you have to create a Book object first and "manually" link
it to the Author object. I think Doctrine handles 1:1 relationships
automatically, but Propel may not. I'm not sure about that. But I
guess if you take the manual approach from the example above, you may
have a good starting point :)

Also be sure to read through some of the messages posted to that TRAC
discussion, they really helped me grasp the concept of embedded forms
a bit better! ;)

Regards,

Thiago Campezzi



On Jun 29, 7:12 am, "Java geek"  wrote:
> Sorry, there was a typo...
>
> Here's the code.
>
> Schema
> propel:
>
>   user:
>     id: ~
>     name: {type: varchar(100)}
>
>   registrations:
>     id: ~
>     user_id: {type: integer, foreignTable: user, foreignReference: id, 
> required: true}
>
> RegistrationForm
>
> class RegistrationsForm extends BaseRegistrationsForm
> {
>   public function configure()
>   {
>     unset($this['user_id']);
>     $userform = new UserForm($this->object->getUser());
>     $this->embedForm("User", $userform);  
>   }
>
> }
>
> UserForm
> class UserForm extends BaseUserForm
> {
>   public function configure()
>   {
>   }
>
> }
>
> If I don't use required = true in required: true, in that case.. user is 
> saved in db.. but still user_id is null in registration, so no association is 
> made, user_id is not getting set.
>
>   - Original Message -
>   From: Java geek
>   To: symfony-users@googlegroups.com
>   Sent: Monday, June 29, 2009 3:27 PM
>   Subject: [symfony-users] Re: Foreign key violation when saving embedded 
> forms
>
>   I am using Symfony 1.2 and propel...
>     - Original Message -
>     From: Java geek
>     To: symfony-users@googlegroups.com
>     Sent: Monday, June 29, 2009 2:30 PM
>     Subject: [symfony-users] Foreign key violation when saving embedded forms
>
>     I have following schema.
>
> User
>   id: ~
>   name: {type: varchar(100)}
>
> Registrations
>   id: ~
>   user_id: {type: integer, foreignTable: User, foreignReference: id}
>
>     schema is not complete, It shows important fields only.
>
>     RegistrationForm
>
> unset($this['user_id']);
> $userform = new UserForm($this->object->getUser());
> $this->embedForm($userform);
>
>     Form is displayed.. and it works when updating existing registrations.
>
>     But it throws foreign key constraint violation when creating new 
> registrations. because user_id is null. Some how new user is not being set on 
> registration.
>
>     What am I doing wrong?
>
>     SN
>    http://www.jsptube.com
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: Foreign key violation when saving embedded forms

2009-06-29 Thread Java geek
Sorry, there was a typo... 

Here's the code.


Schema
propel:
  
  user:
id: ~
name: {type: varchar(100)}

  registrations:
id: ~
user_id: {type: integer, foreignTable: user, foreignReference: id, 
required: true} 


RegistrationForm

class RegistrationsForm extends BaseRegistrationsForm
{
  public function configure()
  {
unset($this['user_id']);
$userform = new UserForm($this->object->getUser());
$this->embedForm("User", $userform);  
  }
}

UserForm
class UserForm extends BaseUserForm
{
  public function configure()
  {
  }
}


If I don't use required = true in required: true, in that case.. user is saved 
in db.. but still user_id is null in registration, so no association is made, 
user_id is not getting set.
  - Original Message - 
  From: Java geek 
  To: symfony-users@googlegroups.com 
  Sent: Monday, June 29, 2009 3:27 PM
  Subject: [symfony-users] Re: Foreign key violation when saving embedded forms


  I am using Symfony 1.2 and propel... 
- Original Message - 
From: Java geek 
To: symfony-users@googlegroups.com 
Sent: Monday, June 29, 2009 2:30 PM
Subject: [symfony-users] Foreign key violation when saving embedded forms


I have following schema.

User
  id: ~
  name: {type: varchar(100)}
  
Registrations
  id: ~
  user_id: {type: integer, foreignTable: User, foreignReference: id}


schema is not complete, It shows important fields only.

RegistrationForm


unset($this['user_id']);
$userform = new UserForm($this->object->getUser());
$this->embedForm($userform);


Form is displayed.. and it works when updating existing registrations.

But it throws foreign key constraint violation when creating new 
registrations. because user_id is null. Some how new user is not being set on 
registration.

What am I doing wrong?

SN
http://www.jsptube.com


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: Foreign key violation when saving embedded forms

2009-06-29 Thread Java geek
I am using Symfony 1.2 and propel... 
  - Original Message - 
  From: Java geek 
  To: symfony-users@googlegroups.com 
  Sent: Monday, June 29, 2009 2:30 PM
  Subject: [symfony-users] Foreign key violation when saving embedded forms


  I have following schema.

User
  id: ~
  name: {type: varchar(100)}
  
Registrations
  id: ~
  user_id: {type: integer, foreignTable: User, foreignReference: id}


  schema is not complete, It shows important fields only.

  RegistrationForm


unset($this['user_id']);
$userform = new UserForm($this->object->getUser());
$this->embedForm($userform);


  Form is displayed.. and it works when updating existing registrations.

  But it throws foreign key constraint violation when creating new 
registrations. because user_id is null. Some how new user is not being set on 
registration.

  What am I doing wrong?

  SN
  http://www.jsptube.com

  

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---