Doctrine 1.2.4, PHP 5.3.3, all InnoDB tables. There are three tables: profile, stream, event. Connected:


Stream

$this->hasMany('modelEvent as Events', array( 'local' => 'id', 'foreign' => 'stream_id' )); 

Profile

 $this->hasMany('modelEvent as Events', array( 'local' => 'id', 'foreign' => 'profile_id' )); 

Event

  $this->hasOne('modelProfile', array( 'local' => 'profile_id', 'foreign' => 'id' )); $this->hasOne('modelStream', array( 'local' => 'stream_id', 'foreign' => 'id' )); 

 <?php $select = new modelEvent(); $select -> merge ($data_event); $select -> modelProfile -> merge($data_profile); $select -> modelStream -> merge($data_stream); $select -> save(); ?> 

Relation does not work immediately. Appears when adding the third record, and it hooks the Stream with

stream_id = 1

and

profile_id = 1

I suspect that I have made a big mistake somewhere in the documentation. Tell me where.

    2 answers 2

    Try calling save on each model separately:

     $select = new modelEvent(); $select -> merge ($data_event); $select -> modelProfile -> merge($data_profile); $select -> modelStream -> merge($data_stream); $select -> modelProfile -> save(); $select -> modelStream -> save(); $select -> save(); 

      one-to-many

       <?php $profile = new modelProfile(); $profile -> merge($data_profile); $profile -> save(); $select = new modelEvent(); $select = $select -> getTable() -> find(0); $select -> modelProfile = $profile; $select -> save(); ?> 

      back

       <?php $profile = new modelProfile(); /* ... */ $profile -> modelEvent[0] -> merge($event); $profile -> save(); ?> 

      the question is closed