Ejemplo n.º 1
0
 /**
  * Return a Jam_Query_Builder_Join object to allow a query to join with this association
  * You can join polymorphic association only when you pass an alias, wich will be used as the
  * name of the model to match to the polymorphic_key
  *
  * @param  string $alias table name alias
  * @param  string $type  join type (LEFT, NATURAL)
  * @return Jam_Query_Builder_Join
  */
 public function join($alias, $type = NULL)
 {
     if ($this->is_polymorphic()) {
         $foreign_model = $alias;
         if (!$foreign_model) {
             throw new Kohana_Exception('Jam does not join automatically polymorphic belongsto associations!');
         }
         $join = new Jam_Query_Builder_Join($foreign_model, $type);
         $join->on(DB::expr(':model', array(':model' => $foreign_model)), '=', $this->polymorphic);
     } else {
         $join = new Jam_Query_Builder_Join($alias ? array($this->foreign_model, $alias) : $this->foreign_model, $type);
     }
     return $join->context_model($this->model)->on(':primary_key', '=', $this->foreign_key);
 }