generated from MasoniteFramework/starter-package
-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f23adbd
commit de1df45
Showing
4 changed files
with
56 additions
and
7 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
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,34 @@ | ||
import unittest | ||
from src.masoniteorm.models import Model | ||
|
||
class User(Model): | ||
__connection__ = "t" | ||
|
||
@property | ||
def profile(self): | ||
return self.has_one(Profile, "user_id", "id") | ||
|
||
class Profile(Model): | ||
__connection__ = "t" | ||
|
||
|
||
class TestRelatinships(unittest.TestCase): | ||
|
||
def test_can_get_owner_value(self): | ||
user = User.find(1) | ||
self.assertEqual(user.name, "bill") | ||
|
||
def test_can_get_has_one_related_value(self): | ||
user = User.find(1) | ||
self.assertEqual(user.name, "bill") | ||
self.assertEqual(user.profile.title, "title") | ||
|
||
def test_can_get_has_one_query_builder(self): | ||
user = User.find(1) | ||
self.assertEqual(user.name, "bill") | ||
self.assertEqual(user.profile().to_sql(), 'SELECT * FROM "profiles" WHERE "profiles"."user_id" = \'1\'') | ||
|
||
def test_can_get_eager_load_from_builder(self): | ||
user = User.with_("profile").find(1) | ||
self.assertEqual(user.name, "bill") | ||
self.assertEqual(user.profile.title, 'title') |