Example #1
0
 /**
  * @param Database $database
  * The database to write to
  *
  * @param ModelOne $model
  * The source model of the association
  *
  * @return void
  */
 public function write(Database $database, ModelOne $model)
 {
     // Ensure that we've initialized this model
     $this->schema->initializeOnce($database);
     $write_closure = $this->write_closure;
     $primary_key_value = $model->primaryKeyValue();
     foreach ($write_closure($model) as $key => $value) {
         // Write the association
         $query = $this->schema->queryForInsert(['source_pk' => $primary_key_value, 'value' => $value]);
         $database->exec($query);
     }
 }
 /**
  * @param Database $database
  * The database to write to
  *
  * @param ModelOne $model
  * The source model of the association
  *
  * @return void
  */
 public function write(Database $database, ModelOne $model)
 {
     // Ensure that we've initialized this model
     $this->schema->initializeOnce($database);
     $write_closure = $this->write_closure;
     $source_pk = $model->primaryKeyValue();
     foreach ($write_closure($model) as $key => $target) {
         // Write the target out
         $target->write($database);
         // Write the association
         $query = $this->schema->queryForInsert(['source_pk' => $source_pk, 'target_pk' => (string) $target->primaryKeyValue()]);
         $database->exec($query);
     }
 }
Example #3
0
 public static function read(Database $database, $primary_key_value) : CalledBy
 {
     return parent::read($database, $primary_key_value);
 }
Example #4
0
 /**
  * @param Database $database
  * A database to write this model to
  *
  * @return void
  */
 public function write(Database $database)
 {
     parent::write($database);
     $this->primary_key_value = $database->lastInsertRowID();
 }