Skip to content

Commit

Permalink
Fix for jpfuentes2GH-68 on greut fork
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoberley committed Jul 27, 2011
1 parent addc096 commit 2e19dfa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,7 @@ public function load(Model $model) {

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

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

Expand Down
9 changes: 9 additions & 0 deletions test/RelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ public function test_has_many_through()
$this->assert_equals(3,$hosts[1]->id);
}

public function test_gh68_has_many_through_without_inverse()
{
$property = Property::first();
$amenities = $property->amenities_2->getArrayCopy();

$this->assert_equals(1, $amenities[0]->amenity_id);
$this->assert_equals(2, $amenities[1]->amenity_id);
}

public function test_gh27_has_many_through_with_explicit_keys()
{
$property = Property::first();
Expand Down
4 changes: 3 additions & 1 deletion test/models/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class Property extends ActiveRecord\Model

static $has_many = array(
'property_amenities',
array('amenities', 'through' => 'property_amenities')
array('amenities', 'through' => 'property_amenities'),
array('property_amenities_2', 'class_name' => 'PropertyAmenity'),
array('amenities_2', 'class_name' => 'Amenity', 'through' => 'property_amenities_2'),
);
};
?>

0 comments on commit 2e19dfa

Please sign in to comment.