コード例 #1
0
ファイル: Belongsto.php プロジェクト: openbuildings/jam
 /**
  * Automatically sets foreign to sensible defaults.
  *
  * @param   string  $model
  * @param   string  $name
  * @return  void
  */
 public function initialize(Jam_Meta $meta, $name)
 {
     parent::initialize($meta, $name);
     if (!$this->foreign_key) {
         $this->foreign_key = $name . '_id';
     }
     if ($this->foreign_key === $name) {
         throw new Kohana_Exception('In association ":name" for model ":model" - invalid foreign_key name. Field and Association cannot be the same name', array(':model' => $this->model, ':name' => $name));
     }
     $meta->field($this->foreign_key, Jam::field('integer', array_merge($this->_default_field_options, $this->field_options)));
     if ($this->is_polymorphic()) {
         if (!is_string($this->polymorphic)) {
             $this->polymorphic = $name . '_model';
         }
         $meta->field($this->polymorphic, Jam::field('string', array('convert_empty' => TRUE)));
     } elseif (!$this->foreign_model) {
         $this->foreign_model = $name;
     }
     if ($this->count_cache) {
         if ($this->is_polymorphic()) {
             throw new Kohana_Exception('Cannot use count cache on polymorphic associations');
         }
         if ($this->count_cache === TRUE) {
             $this->count_cache = Inflector::plural($this->model) . '_count';
         }
     }
 }
コード例 #2
0
ファイル: Collection.php プロジェクト: Konro1/pms
 /**
  * Assign default forein_model to singular association name
  * @param  Jam_Meta $meta
  * @param  string   $name
  */
 public function initialize(Jam_Meta $meta, $name)
 {
     if (!$this->foreign_model) {
         $this->foreign_model = Inflector::singular($name);
     }
     parent::initialize($meta, $name);
 }
コード例 #3
0
ファイル: Hasone.php プロジェクト: sdipchikov/jam
 /**
  * Automatically sets foreign to sensible defaults.
  *
  * @param   string  $model
  * @param   string  $name
  * @return  void
  */
 public function initialize(Jam_Meta $meta, $name)
 {
     parent::initialize($meta, $name);
     if (!$this->foreign_model) {
         $this->foreign_model = $name;
     }
     if (!$this->foreign_key) {
         $this->foreign_key = $this->model . '_id';
     }
     // Polymorphic associations
     if ($this->as) {
         $this->foreign_key = $this->as . '_id';
         if (!$this->polymorphic_key) {
             $this->polymorphic_key = $this->as . '_model';
         }
     }
 }