Skip to content

Commit be44797

Browse files
committed
BaseRelationship: s/self/instance
1 parent c11fcc4 commit be44797

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ If you are interested in the project then it would be a great idea to read the "
1212

1313
## Issues
1414

15-
Everything really should start with opening an issue or finding an issue. If you feel you have an idea for how the project can be improved, no matter how small, you should open an issue so we can have an open dicussion with the maintainers of the project.
15+
Everything really should start with opening an issue or finding an issue. If you feel you have an idea for how the project can be improved, no matter how small, you should open an issue so we can have an open discussion with the maintainers of the project.
1616

1717
We can discuss in that issue the solution to the problem or feature you have. If we do not feel it fits within the project then we will close the issue. Feel free to open a new issue if new information comes up.
1818

src/masoniteorm/relationships/BaseRelationship.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __get__(self, instance, owner):
5252
object -- Either returns a builder or a hydrated model.
5353
"""
5454
attribute = self.fn.__name__
55-
relationship = self.fn(self)()
55+
relationship = self.fn(instance)()
5656
self.set_keys(instance, attribute)
5757
self._related_builder = relationship.builder
5858

tests/mssql/builder/test_mssql_query_builder_relationships.py

+34
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ def articles(self):
4040
def profile(self):
4141
return Profile
4242

43+
@belongs_to("id", "parent_dynamic_id")
44+
def parent_dynamic(self):
45+
return self.__class__
46+
47+
@belongs_to("id", "parent_specified_id")
48+
def parent_specified(self):
49+
return User
50+
4351

4452
class BaseTestQueryRelationships(unittest.TestCase):
4553
maxDiff = None
@@ -64,6 +72,32 @@ def test_has(self):
6472
""")""",
6573
)
6674

75+
def test_has_reference_to_self(self):
76+
builder = self.get_builder()
77+
sql = builder.has("parent_dynamic").to_sql()
78+
79+
print(sql)
80+
81+
self.assertEqual(
82+
sql,
83+
"""SELECT * FROM [users] WHERE EXISTS ("""
84+
"""SELECT * FROM [users] WHERE [users].[parent_dynamic_id] = [users].[id]"""
85+
""")""",
86+
)
87+
88+
def test_has_reference_to_self_using_class(self):
89+
builder = self.get_builder()
90+
sql = builder.has("parent_specified").to_sql()
91+
92+
print(sql)
93+
94+
self.assertEqual(
95+
sql,
96+
"""SELECT * FROM [users] WHERE EXISTS ("""
97+
"""SELECT * FROM [users] WHERE [users].[parent_specified_id] = [users].[id]"""
98+
""")""",
99+
)
100+
67101
def test_where_has_query(self):
68102
builder = self.get_builder()
69103
sql = builder.where_has("articles", lambda q: q.where("active", 1)).to_sql()

tests/mysql/model/test_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def test_attribute_check_with_hasattr(self):
316316
self.assertFalse(hasattr(Profile(), "__password__"))
317317

318318

319-
if os.getenv("RUN_MYSQL_DATABASE", None).lower() == "true":
319+
if os.getenv("RUN_MYSQL_DATABASE", "false").lower() == "true":
320320

321321
class MysqlTestModel(unittest.TestCase):
322322
# TODO: these tests aren't getting run in CI... is that intentional?

0 commit comments

Comments
 (0)