Skip to content

Commit

Permalink
Merge pull request #20 from flightphp/double-join-fix
Browse files Browse the repository at this point in the history
fixed duplicated sql syntax if join called twice.
  • Loading branch information
n0nag0n authored Jul 30, 2024
2 parents f4b6d70 + b9a5210 commit 3b52872
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ protected function resetQueryData(): self
{
$this->params = [];
$this->sqlExpressions = [];
$this->join = null;
return $this;
}
/**
Expand Down
26 changes: 26 additions & 0 deletions tests/ActiveRecordPdoIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,32 @@ public function testJoin()
$this->assertEquals($user->address, $contact->address);
}

public function testJoinIsClearedAfterCalledTwice()
{
$user = new User(new PDO('sqlite:test.db'));
$user->name = 'demo';
$user->password = md5('demo');
$user->insert();

$contact = new Contact(new PDO('sqlite:test.db'));
$contact->user_id = $user->id;
$contact->email = '[email protected]';
$contact->address = 'test address';
$contact->insert();

$user->select('*, c.email, c.address')->join('contact as c', 'c.user_id = user.id')->find();
// email and address will stored in user data array.
$this->assertEquals($user->id, $contact->user_id);
$this->assertEquals($user->email, $contact->email);
$this->assertEquals($user->address, $contact->address);

$user->select('*, c.email, c.address')->join('contact as c', 'c.user_id = user.id')->find();
// email and address will stored in user data array.
$this->assertEquals($user->id, $contact->user_id);
$this->assertEquals($user->email, $contact->email);
$this->assertEquals($user->address, $contact->address);
}

public function testQuery()
{
$user = new class (new PDO('sqlite:test.db')) extends User {
Expand Down

0 comments on commit 3b52872

Please sign in to comment.