Beispiel #1
0
 /**
  * Add the relationship
  *
  * @return Schema
  * @author Justin Palmer
  **/
 private function addRelationship($name, $type)
 {
     $options = new stdClass();
     $options->name = $name;
     $options->type = $type;
     $options->alias = Inflections::underscore(str_replace('-', '_', $name));
     $options->table = Inflections::tableize($options->alias);
     $options->foreign_key = Inflections::foreignKey(Inflections::singularize($this->model->table_name()));
     $this->relationships->set($name, $options);
     $options->on = $this->autoGenerateOn($name);
     $this->relationships->set($name, $options);
     return $this;
 }
Beispiel #2
0
 /**
  * Add reference to another table
  *
  * @return void
  * @author Justin Palmer
  **/
 public function references($table, $options = '')
 {
     $column = Inflections::tableize($table) . '_id';
     $this->integer($column, $options);
     $this->index($this->table, $column);
 }
Beispiel #3
0
 /**
  * Constructor
  *
  * @param array $array
  * @return Model
  * @author Justin Palmer
  **/
 public function __construct($array = array())
 {
     $Adapter = Adapter::getDriverClass();
     //Generate the table name if it is not set.
     if ($this->table_name === null) {
         $this->table_name = Inflections::tableize(get_class($this));
     }
     //
     $this->schema = new Schema($this);
     $this->alias = Inflections::singularize($this->table_name);
     $this->errors = new Hash();
     //Store the db adapter.
     self::$db = new $Adapter($this);
     //Set the default database name;
     $config = $this->db()->getConfig();
     $this->database_name = $config->database;
     $this->props = new Hash();
     //Hold the columns from the db to make sure properties, rules and relationships set actually exist.
     $this->columns = $this->prepareShowColumns($this->showColumns());
     $this->setProperties($array);
     $this->init();
 }