/**
  * @param string $table_name
  * The table storing the primary key association
  *
  * @param string $target_model_name
  * The name of the target model class
  *
  * @param \Closure $read_closure
  * A closure that accepts a map from keys to models
  * that are to be handled by the source model
  *
  * @param \Closure $write_closure
  * A closure that returns an array mapping string keys
  * to model objects that will be written.
  */
 public function __construct(string $table_name, string $target_model_name, \Closure $read_closure, \Closure $write_closure)
 {
     $schema = new Schema($table_name, [new Column('id', Column::TYPE_INT, true, true), new Column('source_pk', 'STRING'), new Column('target_pk', 'STRING')]);
     /*
     $schema->addCreateQuery(
         "CREATE UNIQUE INDEX IF NOT EXISTS {$table_name}_source_pk_value ON `$table_name` "
         . " (source_pk, value)"
     );
     */
     parent::__construct($schema, $read_closure, $write_closure);
     $this->target_model_name = $target_model_name;
 }
示例#2
0
 /**
  * @param string $table_name
  * The table we'll be interacting with
  *
  * @param string $item_sql_type
  * The type of items being stored
  *
  * @param \Closure $read_closure
  * A closure that accepts a map from keys to models
  * that are to be handled by the source model
  *
  * @param \Closure $write_closure
  * A closure that returns an array mapping string keys
  * to model objects that will be written.
  */
 public function __construct(string $table_name, string $item_sql_type, \Closure $read_closure, \Closure $write_closure)
 {
     $schema = new Schema($table_name, [new Column('id', Column::TYPE_INT, true, true), new Column('source_pk', 'STRING'), new Column('value', $item_sql_type)]);
     $schema->addCreateQuery("CREATE UNIQUE INDEX IF NOT EXISTS {$table_name}_source_pk_value ON `{$table_name}` " . " (source_pk, value)");
     parent::__construct($schema, $read_closure, $write_closure);
 }