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 7577017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:04:44+00:00 2026-05-30T17:04:44+00:00

I used to play with embedded relation/forms with Symfony 1.4 but I’ve a problem

  • 0

I used to play with embedded relation/forms with Symfony 1.4 but I’ve a problem I can’t resolve.

What I want to do is :

  • When a user create a new Event, I embed the relation/forms for the destination and the departure
  • The user could be able to select an existing city via the sfWidgetFormJQueryAutocompleter and if the city do not exist in the DB, the new city is inserted and the association between the departure/destination and the Event is made.

I tried to simply embed relation like that in my city form

public function configure() {
  parent::configure(); 
  unset($this['city_departure_id']);
  unset($this['city_destination_id']);

  $this->embedRelation('Departure', new MyCityForm($this->getObject()->getDeparture()));
  $this->embedRelation('Destination', new MyCityForm($this->getObject()->getDestination()));
  ...
}

If there is a new city, it works but when i get back an existing city (id, name and country are correclty populated), it fail by saying Id Invalid.

What I tried to do is to correct my default validator for the id and convert the base validator (sfValdidatorChoice) into

$this->setValidator('id', new sfValidatorPass(array('required' => false)));

It pass the validation but fail because Symfony try to create a new object with exactly same value.

Now I tried to override the save method for the City into something like that :

public function save(Doctrine_Connection $con = null) {

        if ($this->isNew() && $this->getId() != "") {

            return $this;
        }
        return parent::save($con);
    }

Now it create cities when needed but not when they’re already exist.

My new problem is that fail on the event insertion. It throw a new Exception saying:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'city_destination_id' cannot be null

(in this case, the city_departure was a new one and the destination an existing one)

Here is my schema.yml

Event:
  connection: doctrine
  tableName: sortie
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    description:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    start_date:
      type: date(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    city_departure_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    city_destination_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    Departure:
      local: city_departure__id
      foreign: id
      class: City
      type: one
    Destination:
      class: City
      local: city_destination_id
      foreign: id
      type: one
City:
  connection: doctrine
  tableName: localite
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    name:
      type: string(100)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    country:
      type: string(100)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    Departures:
      local: id
      foreign: localite_depart_id
      type: many
    Destinations:
      class: Sortie
      local: id
      foreign: localite_destination_id
      type: many
  • 1 1 Answer
  • 0 Views
  • 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-30T17:04:45+00:00Added an answer on May 30, 2026 at 5:04 pm

    Ok after a long day I found a solution… But I’m not sure it’s the most correct solution…

    I override the doSave method in my form. After the updateObject call, I check if ids are present in values or not. It seems to work…

    protected function doSave($con = null) {
        if (null === $con)
        {
          $con = $this->getConnection();
        }
    
        $this->updateObject();
    
        $v = $this->getValues();
        if (isset($v['Departure']['id']))
            $this->getObject()->setCityDepartureId($v['Departure']['id']);
        if (isset($v['Destination']['id']))
            $this->getObject()->setCityDestinationId($v['Destination']['id']);
    
        $this->getObject()->save($con);
    
        // embedded forms
        $this->saveEmbeddedForms($con);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

mciSendStringi(,,,); I used the above function to play a mp3 file. Now I want
Never used a cache like this before. The problem is that I want to
I want to play a video in my iPhone app. I used this code:
How to Play Video on OnCreate Method? I Used Following code for that.But The
I am not new to Flash but I have not properly used it for
I'm confused about how VideoView can be used to play video: from a local
I want to deploy an app in Heroku to try their new Play! Framework
In the past I have used Managed Direct X and DirectShow.Net to play a
I used the LINQ to SQL designer in Visual Studio to create an object
I embedded an mp3 file be used as background music for my app. Though

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.