Ejemplo n.º 1
0
 /**
  * Creates a new model object.
  * Accepted parameters:
  * @param array $params {
  * @var string $table defaults to pluralized class name. E.g. customer_orders for CustomerOrder
  * @var string $primaryKey defaults to id
  * @var string $sequence defaults to table_primaryKey_seq
  * @var string $hasMany specification of a has-many relation e.g. array('name' => array('class' => 'Class', 'foreignKey' => 'foreignKey'))
  * @var string $hasOne specification of a has-one relation e.g. array('name' => array('class' => 'Class', 'foreignKey' => 'foreignKey'))
  * @var string $belongsTo specification of a belongs-to relation e.g. array('name' => array('class' => 'Class', 'foreignKey' => 'foreignKey'))
  * @var string $fields mapped column names
  * @var string $attributes array of column => value
  * @var string $beforeSave function to invoke before insert or update
  * @var string $afterSave function to invoke after insert or update
  * }
  */
 public function __construct(array $params)
 {
     $this->_prepareParameters($params);
     $this->_modelDefinition = ModelDefinition::get(get_called_class(), $params);
     $primaryKeyName = $this->_modelDefinition->primaryKey;
     $attributes = $this->_modelDefinition->mergeWithDefaults($params['attributes'], $params['fields']);
     if (isset($attributes[$primaryKeyName]) && Strings::isBlank($attributes[$primaryKeyName])) {
         unset($attributes[$primaryKeyName]);
     }
     $this->_attributes = $this->filterAttributes($attributes);
     $this->_modifiedFields = array_keys($this->_attributes);
 }
Ejemplo n.º 2
0
 public function setUp()
 {
     parent::setUp();
     ModelDefinition::resetCache();
 }