/** * This constructor initializes the class. * * @access public * @override * @param DB_ORM_Model $model a reference to the implementing model * @param array $metadata the relation's metadata */ public function __construct(DB_ORM_Model $model, array $metadata = array()) { parent::__construct($model, 'has_many'); // the parent model is the referenced table $parent_model = get_class($model); // Get parent model's name into variable, otherways a late static binding code throws a // syntax error when used like this: $this->metadata['parent_model']::primary_key() $this->metadata['parent_model'] = $parent_model; // the parent key (i.e. candidate key) is an ordered list of field names in the parent model $this->metadata['parent_key'] = isset($metadata['parent_key']) ? (array) $metadata['parent_key'] : $parent_model::primary_key(); // the through model is the pivot table if (isset($metadata['through_model'])) { $this->metadata['through_model'] = DB_ORM_Model::model_name($metadata['through_model']); } // the through keys is an array of two ordered lists of fields names: [0] matches with parent key and [1] matches with child key if (isset($metadata['through_keys'])) { $this->metadata['through_keys'] = (array) $metadata['through_keys']; } // the child model is the referencing table $this->metadata['child_model'] = DB_ORM_Model::model_name($metadata['child_model']); // the child key (i.e. foreign key) is an ordered list of field names in the child model $this->metadata['child_key'] = (array) $metadata['child_key']; // a set of options that will modify the query $this->metadata['options'] = isset($metadata['options']) ? (array) $metadata['options'] : array(); }
/** * This constructor initializes the class. * * @access public * @override * @param DB_ORM_Model $model a reference to the implementing model * @param array $metadata the relation's metadata */ public function __construct(DB_ORM_Model $model, array $metadata = array()) { parent::__construct($model, 'has_one'); // the parent model is the referenced table $parent_model = get_class($model); // Get parent model's name into variable, otherways a late static binding code throws a // syntax error when used like this: $this->metadata['parent_model']::primary_key() $this->metadata['parent_model'] = $parent_model; // the parent key (i.e. candidate key) is an ordered list of field names in the parent model $this->metadata['parent_key'] = isset($metadata['parent_key']) ? (array) $metadata['parent_key'] : $parent_model::primary_key(); // the child model is the referencing table $this->metadata['child_model'] = DB_ORM_Model::model_name($metadata['child_model']); // the child key (i.e. foreign key) is an ordered list of field names in the child model $this->metadata['child_key'] = (array) $metadata['child_key']; }