/** * Return a Jam_Query_Builder_Join object to allow a query to join with this association * @param string $alias table name alias * @param string $type join type (LEFT, NATURAL) * @return Jam_Query_Builder_Join */ public function join($alias, $type = NULL) { $join = Jam_Query_Builder_Join::factory($this->join_table, $type)->context_model($this->model)->model($this->foreign_model)->on($this->join_table . '.' . $this->foreign_key, '=', ':primary_key'); if ($this->join_table_paranoid) { $join->on($this->join_table . '.' . $this->join_table_paranoid, '=', DB::expr('0')); } return $join->join_table($alias ? array($this->foreign_model, $alias) : $this->foreign_model, $type)->on(':primary_key', '=', $this->join_table . '.' . $this->association_foreign_key)->context_model($this->model)->end(); }
/** * Return a Jam_Query_Builder_Join object to allow a query to join with this association * @param string $alias table name alias * @param string $type join type (LEFT, NATURAL) * @return Jam_Query_Builder_Join */ public function join($alias, $type = NULL) { $join = Jam_Query_Builder_Join::factory($alias ? array($this->foreign_model, $alias) : $this->foreign_model, $type)->context_model($this->model)->on($this->foreign_key, '=', ':primary_key'); if ($this->is_polymorphic()) { $join->on($this->polymorphic_key, '=', DB::expr(':model', array(':model' => $this->model))); } return $join; }
public function join($alias, $type = NULL) { $join = Jam_Query_Builder_Join::factory($this->join_table, $type)->context_model($this->model)->model($this->foreign_model)->on($this->join_table . '.' . $this->item_key, '=', ':primary_key')->on($this->join_table . '.' . $this->item_polymorphic_key, '=', DB::expr(':model', array(':model' => $this->model))); $join_nested = $join->join_table($alias ? array($this->foreign_model, $alias) : $this->foreign_model, $type)->context_model($this->model)->on(':primary_key', '=', $this->join_table . '.' . $this->term_key); if ($this->vocabulary_ids()) { $join_nested->on($this->vocabulary_foreign_key, 'IN', DB::expr(':ids', array(':ids' => $this->vocabulary_ids()))); } return $join; }
public function join($alias, $type = NULL) { return Jam_Query_Builder_Join::factory($this->join_table, $type)->context_model($this->model)->model($this->foreign_model)->on($this->join_table . '.' . $this->item_key, '=', ':primary_key')->on(DB::expr(':model', array(':model' => $this->foreign_model)), '=', $this->join_table . '.' . $this->item_polymorphic_key)->join_table($alias ? array($this->foreign_model, $alias) : $this->foreign_model, $type)->on(':primary_key', '=', $this->join_table . '.' . $this->term_key)->context_model($this->model)->end(); }
/** * 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); }
/** * Return a Jam_Query_Builder_Join object to allow a query to join with this association * @param string $alias table name alias * @param string $type join type (LEFT, NATURAL) * @return Jam_Query_Builder_Join */ public function join($alias, $type = NULL) { return Jam_Query_Builder_Join::factory($this->branches_table, $type)->context_model($this->model)->model($this->foreign_model)->on($this->branches_table . '.' . $this->ansestor_key, '=', ':primary_key')->join_table($alias ? array($this->foreign_model, $alias) : $this->foreign_model, $type)->on(':primary_key', '=', $this->branches_table . '.' . $this->descendant_key)->on(DB::expr(':depth', array(':depth' => 1)), '>=', $this->branches_table . '.' . $this->depth_key)->context_model($this->model)->end(); }
public function test_nested_joins() { $join = Jam_Query_Builder_Join::factory('test_post')->join_nested('test_blog')->join('test_posts')->end(); $this->assertEquals('JOIN `test_posts` ON () JOIN `test_blogs` ON (`test_blogs`.`id` = `test_posts`.`test_blog_id`) JOIN `test_posts` ON (`test_posts`.`test_blog_id` = `test_blogs`.`id`)', (string) $join); }
/** * Generate Jam_Query_Builder_Join based on the given arguments * @param string $table * @param string $type LEFT, NATURAL... * @param string $context_model the model of the parent * @param boolean $resolve_table_model wether to resolve the name of the model to a tablename * @return Jam_Query_Builder_Join */ public static function resolve_join($table, $type = NULL, $context_model = NULL, $resolve_table_model = TRUE) { $context_model_name = Jam_Query_Builder::aliased_model($context_model); if ($resolve_table_model and is_string($context_model_name) and $meta = Jam::meta($context_model_name)) { $table_name = Jam_Query_Builder::aliased_model($table); if (is_string($table_name) and $association = $meta->association($table_name)) { return $association->join(is_array($table) ? $table[1] : NULL, $type); } } $join = Jam_Query_Builder_Join::factory($table, $type); if ($context_model) { $join->context_model($context_model); } return $join; }