I would try instead of $artiste->setIdFiche($a); something like
$artiste->setFiche($fiche);


On 22 čvn, 15:10, titiyoyo <terence.pi...@gmail.com> wrote:
> Well now i get the Id.
> But basically what i did was i merged two forms (from Artiste and
> Fiche models) and tried to create a new Artiste from a form, and set
> the Fiche foreign key directly in the controler.
>
> I don't have the exact code here but it looks like this below.
>
> All this creates a new Fiche and a new Artiste, but it doesn't inserts
> the new Fiche id in the Artiste table. So no link is created between
> the two tables.
> Which is what it only lacks...
>
> //Form for Artiste model
> class ArtisteForm extends BaseArtisteForm
> {
>   public function configure()
>   {
>     unset(
>       $this['id_fiche']
>     );
>
>     $this->merge(new Fiche());
>   }
>
> }
>
> //controler for Artiste model
>   public function executeNew(sfWebRequest $request)
>   {
>         $fiche = new Fiche();
>         $fiche->save();
>         $artiste = new Artiste();
>         $a = $fiche->getId();
>
>         $artiste->setIdFiche($a);
>
>         $this->form = new ArtisteForm($artiste);
>   }
>
> On 21 juin, 15:06, titiyoyo <terence.pi...@gmail.com> wrote:
>
>
>
>
>
> > Hi there
>
> > thanks for that.
>
> > for now i have this :
>
> >   public function executeNew(sfWebRequest $request)
> >   {
> >         $fiche = new Fiche();
> >         $fiche->save();
> >         $artiste = new Artiste();
> >         $a = $fiche->getId();
>
> >         $artiste->setIdFiche($a);
>
> >         $this->form = new ArtisteForm($artiste);
> >   }
>
> > i got the needed id in $a, but when the form is saved no id is written
> > in db...
>
> > On 21 juin, 09:00, Tom Ptacnik <to...@tomor.cz> wrote:
>
> > > I think that the solution might be owerwriting the doSave method .. or
> > > some method where the saving of the object is done. You need to save
> > > the foreign object first - to obtain the id from the database, then
> > > save the main object.
>
> > > On 19 čvn, 12:24, titiyoyo <terence.pi...@gmail.com> wrote:
>
> > > > Hi there,
>
> > > > i'm new to symfony and am bumping into a problem here.
> > > > I merged two forms from 2 different models and need to get a foreign
> > > > key from table A to put in this table B form.
>
> > > > Basically, i have to
> > > > - create a record in table A and get this record's id
> > > > - create a record in table B an set it's table_a_id to the value i
> > > > just got
> > > > - fill out the rest of the info that will be put in table B
>
> > > > My question is :
> > > > how can i get the needed id ?
>
> On 22 juin, 14:08, Gareth McCumskey <gmccums...@gmail.com> wrote:
>
> > Quite simple as the new record Id is inserted on save. If you use Propel and
> > have the following for example:
>
> > $obj_to_save = new ModelClass();
> > $obj_to_save->setField1('value1');
> > $obj_to_save->setField2('value2');
> > $obj_to_save->save();
>
> > Then you can get the ID right after save with:
>
> > $obj_to_save->getId(); //Assuming your primary key id feild is called "id"
>
> > On Saturday 19 June 2010 12:24:06 titiyoyo wrote:
>
> > > Hi there,
>
> > > i'm new to symfony and am bumping into a problem here.
> > > I merged two forms from 2 different models and need to get a foreign
> > > key from table A to put in this table B form.
>
> > > Basically, i have to
> > > - create a record in table A and get this record's id
> > > - create a record in table B an set it's table_a_id to the value i
> > > just got
> > > - fill out the rest of the info that will be put in table B
>
> > > My question is :
> > > how can i get the needed id ?

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.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

Reply via email to