Exemplo n.º 1
0
 /**
  * @param Database $database
  * The database to read from
  *
  * @param ModelOne $model
  * The source model of the association
  *
  * @return Model
  * Read a model from the database with the given pk
  */
 public function read(Database $database, ModelOne $model)
 {
     $read_closure = $this->read_closure;
     // Select all rows for this PK from the
     // association table
     $select_query = $this->schema->queryForSelectColumnValue('source_pk', $model->primaryKeyValue());
     $result = $database->query($select_query);
     if (!$result) {
         $read_closure($model, []);
         return;
     }
     $column = [];
     while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
         $column[] = $row['value'];
     }
     // Write the map to the model
     $read_closure($model, $column);
 }