Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test eager loading belongs to nested with same foreign key #538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/RelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,23 @@ public function test_eager_loading_belongs_to_nested()
$this->assert_sql_has("WHERE author_id IN(?,?)",ActiveRecord\Table::load('AwesomePerson')->last_sql);
}

public function test_eager_loading_belongs_to_nested_with_same_foreign_key()
{
Author::$has_many = array(array('awesome_people'));

$books = Book::find(array(2,3), array('include' => array('author' => array('awesome_people'))));

foreach ($books as $book)
{
$this->assert_equals($book->author_id,$book->author->author_id);
$this->assert_equals($book->author->author_id,$book->author->awesome_people[0]->author_id);
}

$this->assert_sql_has("WHERE book_id IN(?,?)",ActiveRecord\Table::load('Book')->last_sql);
$this->assert_sql_has("WHERE author_id IN(?,?)",ActiveRecord\Table::load('Author')->last_sql);
$this->assert_sql_has("WHERE author_id IN(?,?)",ActiveRecord\Table::load('AwesomePerson')->last_sql);
}

public function test_eager_loading_belongs_to_with_no_related_rows()
{
$e1 = Event::create(array('venue_id' => 200, 'host_id' => 200, 'title' => 'blah','type' => 'Music'));
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/books.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
book_id,author_id,secondary_author_id,name,special
1,1,2,"Ancient Art of Main Tanking",0
2,2,2,"Another Book",0
2,2,2,"Another Book",0
3,2,2,"Another Book Extended",0