title: Why is my propel cascade blocked by foreign key constraints?
body: <p>I have the following structure in the databse:</p>
  
  <p><img src="https://i.stack.imgur.com/9We4F.png" alt="enter image description here"></p>
  
  <p>In my code I first create a Company, then a logbook, then a number of schedules, then a user, then a logbook responsibility. Sort of like this (not exact code for conciseness, but I don't <em>think</em> that matters:</p>
  
  <pre><code>&lt;?php
  
  $company = new Company();
  $company-&gt;setSomething(123);
  
  $logbook = new Logbook();
  $logbook-&gt;setSomething('abc');
  $logbook-&gt;setCompany($company);
  
  $schedules = array();
  for ($x=0; $x&lt;$something; $x++) {
    $schedule = new Schedule();
    $schedule-&gt;setSomething(doSomethingWithSomething($something[$x]);
    $schedule-&gt;setLogbook($logbook);
    $schedules[] = $schedule;
  }
  
  $user = new User();
  $user-&gt;setSomething('something');
  $user-&gt;setCompany($company);
  $user-&gt;setCurrentLogbook($logbook);
  
  $logbookResponsibility = new LogbookResponsibility();
  $logbookResponsibility-&gt;setLogbook($logbook);
  $logbookResponsibility-&gt;setResponsibilityId(1);
  $logbookResponsibility-&gt;setUser($user);
  
  $errors = someFormOfCheck();
  
  if (!$errors) {
    $user-&gt;save();
    $logbookResponsibility-&gt;save();
    foreach ($schedules as $schedule) {
      $schedule-&gt;save();
    }
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>&lt;b&gt;Fatal error&lt;/b&gt;:  Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`logbook`.`logbook_responsibility`, CONSTRAINT `fk_logbook_responsbility_user` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE CASCADE)' in C:\wamp\bin\php\php5.3.8\pear\propel\connection\DebugPDOStatement.php:90
  </code></pre>
  
  <p>The <code>logbook_responsibility</code> table is made up of three foreign keys, each which have a <code>RESTRICT</code> on the updates, because I don't want it to be possible to delete a user, logbook or type of responsibility if a logbook responsibility exists. I believe the problem, however, is determined by the order of the cascade.</p>
  
  <p>If I take out the <code>$logbookResponsibility</code> parts altogether, it works perfectly. If I put the <code>$logbookResponsibility</code> parts <em>after</em> the <code>$user-&gt;save();</code> and then issue a <code>$logbookResponsibility-&gt;save();</code> as well, that also works perfectly.</p>
  
  <p>My question, then, is where abouts am I going wrong? What am I presuming incorreclty or doing wrong, to make the cascade work? Or is there something else that might be stopping it?</p>
  
  <p><strong>Update:</strong> If I do the following, it works just fine:</p>
  
  <pre><code>$company-&gt;save();
  $logbook-&gt;save();
  $user-&gt;save();
  $logbookResponsibility-&gt;save();
  foreach ($schedules as $scheudle) {
    $schedule-&gt;save();
  }
  </code></pre>
  
  <p>i.e. if I save them manually first instead of relying on the cascade.</p>