Bug Report #933

ORM many to many linking table aliases

Added by Nowaker - almost 6 years ago. Updated almost 5 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Ben Rogers% Done:

0%

Category:Libraries:ORM
Target version:2.4
Resolution:duplicate Points:

Description

Please revise whether an idea of aliasing many to many linking tables is OK.

class Auth_User_Model extends ORM {

  protected $has_many = array('user_tokens');
  protected $has_and_belongs_to_many = array('user_roles' => 'user_role_links');

}

Replace in has(), add() and remove():

 if (($join_table = array_search(inflector::plural($model->object_name), $this->has_and_belongs_to_many)) === FALSE)
      return FALSE;

Into:
 $relationships = array_values($this->has_and_belongs_to_many);
 if (($join_table = $relationships[array_search(inflector::plural($model->object_name), array_keys($this->has_and_belongs_to_many))]) === FALSE)
      return FALSE;

Replace in function _ _get():
$join_table = $model->join_table($this->table_name);

Into:
if (isset($this->has_and_belongs_to_many[$column]))
{
    $join_table = $this->has_and_belongs_to_many[$column];
}
else
{
    $join_table = $model->join_table($this->table_name);
}

And:
elseif (in_array($column, $this->has_and_belongs_to_many))

Into:
elseif (in_array($column, $this->has_and_belongs_to_many) || array_key_exists($column, $this->has_and_belongs_to_many))

A discussion on the forum: http://forum.kohanaphp.com/comments.php?DiscussionID=1466

MY_ORM.php Magnifier - MY_ORM extension (2.83 KB) Nowaker -, 11/23/2008 09:31 AM


Related issues

Duplicates Kohana v2.x - Bug Report #1215: ORM HABTM Aliases Closed

History

#1 Updated by John Heathco about 5 years ago

  • Assignee changed from Woody Gilk to John Heathco

#2 Updated by Jeremy Bush about 5 years ago

  • Status changed from New to Assigned

#3 Updated by Ben Rogers almost 5 years ago

  • Assignee changed from John Heathco to Ben Rogers

#4 Updated by Ben Rogers almost 5 years ago

  • Status changed from Assigned to Closed
  • Resolution set to duplicate

Also available in: Atom PDF