Skip to content

Commit b9a5210

Browse files
committed
fixed duplicated sql syntax if join called twice.
1 parent f4b6d70 commit b9a5210

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/ActiveRecord.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ protected function resetQueryData(): self
317317
{
318318
$this->params = [];
319319
$this->sqlExpressions = [];
320+
$this->join = null;
320321
return $this;
321322
}
322323
/**

tests/ActiveRecordPdoIntegrationTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,32 @@ public function testJoin()
183183
$this->assertEquals($user->address, $contact->address);
184184
}
185185

186+
public function testJoinIsClearedAfterCalledTwice()
187+
{
188+
$user = new User(new PDO('sqlite:test.db'));
189+
$user->name = 'demo';
190+
$user->password = md5('demo');
191+
$user->insert();
192+
193+
$contact = new Contact(new PDO('sqlite:test.db'));
194+
$contact->user_id = $user->id;
195+
$contact->email = '[email protected]';
196+
$contact->address = 'test address';
197+
$contact->insert();
198+
199+
$user->select('*, c.email, c.address')->join('contact as c', 'c.user_id = user.id')->find();
200+
// email and address will stored in user data array.
201+
$this->assertEquals($user->id, $contact->user_id);
202+
$this->assertEquals($user->email, $contact->email);
203+
$this->assertEquals($user->address, $contact->address);
204+
205+
$user->select('*, c.email, c.address')->join('contact as c', 'c.user_id = user.id')->find();
206+
// email and address will stored in user data array.
207+
$this->assertEquals($user->id, $contact->user_id);
208+
$this->assertEquals($user->email, $contact->email);
209+
$this->assertEquals($user->address, $contact->address);
210+
}
211+
186212
public function testQuery()
187213
{
188214
$user = new class (new PDO('sqlite:test.db')) extends User {

0 commit comments

Comments
 (0)