Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3613908
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:10:57+00:00 2026-05-18T22:10:57+00:00

I have found some useful info on this issue but can’t quite wrap my

  • 0

I have found some useful info on this issue but can’t quite wrap my head around the solutions. So I’m hoping someone can explain to me a helpful solution and not a plugin/hack/workaround I’m trying very hard to do the “Right” way:

So here is what my issue:

schema:

detect_relations: true    
Student:
  tableName: student
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    name:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      default: ''
      notnull: true
      autoincrement: false
    parents_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      default: ''
      notnull: true
      autoincrement: false
   relations:
     Parents:
      refClass: StudentParentLink
      local: student_id
      foreign: parents_id
      onDelete: CASCADE
Parents:
  tableName: parents
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    name:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      default: ''
      notnull: true
      autoincrement: false
    email_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      default: '0'
      notnull: true
      autoincrement: false
    relations:
      Student:
        refClass: StudetParentLink
        local: parents_id
        forign: student_id
        onDelete: CASCADE
Email:
  tableName: email
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    email:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      default: ''
      notnull: true
      autoincrement: false
StudentParentLink:
  tableName: student_parent_link
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    student_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      default: '0'
      notnull: true
      autoincrement: false
    parents_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      default: '0'
      notnull: true
      autoincrement: false

So in english, I have a student who has a parent(s) and that parent(s) has an email address, simple enough.

So in my Student Form I have the following:

 //studentForm.class.php
 public function configure()
 {
     if($this->getObject()->isNew() || count($this->getObject()->Parents) == 0)
     {
         $this->getObject()->Parents[] = new Parents();
     }

     $parentsSubForm = new sfForm();
     $i = 1;
     foreach($this->getObject()->Parents as $parents)
     {
       $parentsForm = new ParentsForm($parents);
       $parentSubForm->embedForm("Parent $i",$parentsForm);
       $i++;
     }
  $this->embedForm('Parents',$parentSubForm)
 }

This looks as expected and works for adding a Student record, however on update I get the error:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2' for key 1

I’m not sure what is happening only that it looks like it’s doing an insert not update for the parent, is that as designed? I just need to be able to add/edit the parents email (and all other data points not listed in this example for simplicity) via the Student Form

As always any direction or comments are very welcome! I am just getting the hang of Symfony and little nuances like this are great to learn so I can move forward!

~ Mahalo Zjoia

UPDATE

So I am desperate here and totally confused, I’ve tried everything I can think of and find and yes I am able to get the error to go away but what is ambiguous in the above schema is EMAIL is Many-to-One so doing things as described in Advance Forms doesn’t work you need to relate it different so I have the following Code:

 if($this->getObject()->isNew() || count($this->getObject()->Email) < 1)
 {
    $email = new Email($this->getObject()->Email);
    $emailForm = new EmailForm($email);
    $this->embedForm('Parents Email', $emailForm);
    $useFields[] = 'Parents Email';
 }else{
    $this->embedRelation('Email');
    $this->widgetSchema['Email']->setLabel('Parents Email');
    $useFields[] = 'Email';
 }

This works just fine if I am in the Parent Form but when I am in the Student Form (which embeds the parents form) it’s not relating the email back to the parent, it creates the Email correctly in the email table but does not insert the email_id in the parent table

I’m going mad with this I just don’t understand, please help!

IDIOT

ANSWER

Turns out I had some old models that were linking tables that I thought a model rebuild would remove turns out not so much, got that removed and all the crazy weirdness is gone, things work perfect!

Always something stupid that is missed

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:10:58+00:00Added an answer on May 18, 2026 at 10:10 pm

    Your problem is very common and described at the symfony website.
    Here is example of what you need.

    Also may be useful this documentation. "Especially Chapter 11 – Doctrine Integration".

    Regards
    Evgeny

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Although I have found some solutions to this problem, none of them refer to
I found some useful information on the web but I still can't manage to
I have found some similar posts, but I didn't find them useful. But I
I have found DoctrineExtensions module that has implement some useful MySQL functions. But I
I have found some jQuery codes for show content with slide effect, but none
I have found some similar Que's on SO but had not find the solution.
I have found some posts related to search on XML but those were not
I have found some code snippet in the internet. But it is missing some
i have found some ways but they are actually reading frames and applying transition
I've searched the Internet and have found some good solutions for teeing STDOUT to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.