Skip to content

Commit 9c43bdb

Browse files
jmoberleykoenpunt
jmoberley
authored andcommitted
Fix for issue 68: relationship references wrong table
Include @suxxes changes
1 parent 54f8d4f commit 9c43bdb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/Relationship.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ public function load(Model $model)
496496
if ($this->through)
497497
{
498498
// verify through is a belongs_to or has_many for access of keys
499-
if (!($through_relationship = $this->get_table()->get_relationship($this->through)))
499+
if (!($through_relationship = $model->table()->get_relationship($this->through)))
500500
throw new HasManyThroughAssociationException("Could not find the association $this->through in model " . get_class($model));
501501

502502
if (!($through_relationship instanceof HasMany) && !($through_relationship instanceof BelongsTo))
@@ -508,8 +508,7 @@ public function load(Model $model)
508508

509509
$this->set_keys($this->get_table()->class->getName(), true);
510510

511-
$class = $this->class_name;
512-
$relation = $class::table()->get_relationship($this->through);
511+
$relation = $model::table()->get_relationship($this->through);
513512
$through_table = $relation->get_table();
514513
$this->options['joins'] = $this->construct_inner_join_sql($through_table, true);
515514

0 commit comments

Comments
 (0)