예제 #1
0
 /**
  * Save the data in the database.
  * 
  * @param Row   $row
  * @param array $data
  */
 protected function save(Row $row, array $data)
 {
     $table = $this->getTable();
     $db = $table->getDatabase();
     $scheme = $table->getScheme();
     foreach ($data as $name => $value) {
         if (isset($scheme['relations'][$name])) {
             $row->unrelateAll($db->{$name});
             $rows = $db->{$name}->select()->by('id', $value)->run();
             foreach ($rows as $r) {
                 $row->relate($r);
             }
         } else {
             $row->{$name} = $value;
         }
     }
     $row->save();
 }
예제 #2
0
 /**
  * Save the data in the database.
  * 
  * @param Row   $row
  * @param array $data
  */
 protected function save(Row $row, array $data)
 {
     $table = $this->getTable();
     $db = $table->getDatabase();
     $scheme = $table->getScheme();
     foreach ($data as $name => $value) {
         if (isset($scheme['fields'][$name])) {
             $row->{$name} = $value;
         }
     }
     foreach ($data as $name => $value) {
         if (isset($scheme['relations'][$name])) {
             $unrelated = $row->{$name}()->where("`{$name}`.`id` NOT IN (:ids)", [':ids' => $value])->run();
             foreach ($unrelated as $r) {
                 $row->unrelate($r);
             }
             $rows = $db->{$name}->select()->by('id', $value)->run();
             foreach ($rows as $r) {
                 $row->relate($r);
             }
         }
     }
     $row->save();
 }