-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* iteration * iteration2 * iteration3 * iteration4 * iteration5 * cs
- Loading branch information
Showing
6 changed files
with
145 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Fico7489\Laravel\EloquentJoin\Tests\Models\Key; | ||
|
||
use Fico7489\Laravel\EloquentJoin\Tests\Models\BaseModel; | ||
|
||
class Location extends BaseModel | ||
{ | ||
protected $primaryKey = 'key_id_location'; | ||
|
||
protected $table = 'key_locations'; | ||
|
||
protected $fillable = ['address', 'seller_id']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Fico7489\Laravel\EloquentJoin\Tests\Models\Key; | ||
|
||
use Fico7489\Laravel\EloquentJoin\Tests\Models\BaseModel; | ||
|
||
class Order extends BaseModel | ||
{ | ||
protected $primaryKey = 'key_id_order'; | ||
|
||
protected $table = 'key_orders'; | ||
|
||
protected $fillable = ['number', 'seller_id']; | ||
|
||
public function seller() | ||
{ | ||
return $this->belongsTo(Seller::class, 'key_seller_id', 'key_id_order'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Fico7489\Laravel\EloquentJoin\Tests\Models\Key; | ||
|
||
use Fico7489\Laravel\EloquentJoin\Tests\Models\BaseModel; | ||
|
||
class Seller extends BaseModel | ||
{ | ||
protected $primaryKey = 'key_id_seller'; | ||
|
||
protected $table = 'key_sellers'; | ||
|
||
protected $fillable = ['title', 'deleted_at']; | ||
|
||
public function location() | ||
{ | ||
return $this->hasOne(Location::class, 'key_seller_id', 'key_id_seller'); | ||
} | ||
|
||
public function locations() | ||
{ | ||
return $this->hasMany(Location::class, 'key_seller_id', 'key_id_seller'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Fico7489\Laravel\EloquentJoin\Tests\Tests; | ||
|
||
use Fico7489\Laravel\EloquentJoin\Tests\Models\Key\Order; | ||
use Fico7489\Laravel\EloquentJoin\Tests\Models\Key\Seller; | ||
use Fico7489\Laravel\EloquentJoin\Tests\TestCase; | ||
|
||
class KeysTest extends TestCase | ||
{ | ||
public function testBelogsTo() | ||
{ | ||
Order::joinRelations('seller') | ||
->get(); | ||
|
||
$queryTest = 'select key_orders.* | ||
from "key_orders" | ||
left join "key_sellers" on "key_sellers"."key_id_seller" = "key_orders"."key_seller_id" | ||
group by "key_orders"."key_id_order"'; | ||
|
||
$this->assertQueryMatches($queryTest, $this->fetchQuery()); | ||
} | ||
|
||
public function testHasOne() | ||
{ | ||
Seller::joinRelations('location') | ||
->get(); | ||
|
||
$queryTest = 'select key_sellers.* | ||
from "key_sellers" | ||
left join "key_locations" on "key_locations"."key_seller_id" = "key_sellers"."key_id_seller" | ||
group by "key_sellers"."key_id_seller"'; | ||
|
||
$this->assertQueryMatches($queryTest, $this->fetchQuery()); | ||
} | ||
|
||
public function testHasMany() | ||
{ | ||
Seller::joinRelations('locations') | ||
->get(); | ||
|
||
$queryTest = 'select key_sellers.* | ||
from "key_sellers" | ||
left join "key_locations" on "key_locations"."key_seller_id" = "key_sellers"."key_id_seller" | ||
group by "key_sellers"."key_id_seller"'; | ||
|
||
$this->assertQueryMatches($queryTest, $this->fetchQuery()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters