M activist/db/sqlbuilder.py => activist/db/sqlbuilder.py +2 -0
@@ 413,6 413,8 @@ class Query(QueryBase):
match k:
case "(":
close = " )"
+ case "JOIN":
+ joiner = " JOIN "
case "WHERE":
joiner = " AND "
case "VALUES":
M tests/orm.py => tests/orm.py +9 -1
@@ 177,4 177,12 @@ class BaseTestOrm(unittest.TestCase):
data = Data.get(2)
self.assertIsInstance(data, Data)
self.assertIsInstance(data.data, JSON)
- self.assertDictEqual(data.data, {"b":3})>
\ No newline at end of file
+ self.assertDictEqual(data.data, {"b":3})
+
+ @with_app_context
+ def test_multiple_join(self):
+ q = Post.query().select()
+ q.join("utente", "post.utente = utente.id")
+ q.join("utente as supervisor", "post.utente = supervisor.id")
+ data = q.get()
+ self.assertIsInstance(data, Post)<
\ No newline at end of file
M tests/test_sqlbuilder.py => tests/test_sqlbuilder.py +5 -0
@@ 321,6 321,11 @@ class Sqlbuilder:
with self.assertRaises(SqlBuilderException):
self.q.join("tablea", "tableb")
+ def test_join_multiple(self):
+ q = self.q.join("tablea", "table" , "condition = condition")
+ q = q.join("tableb", "condition = condition")
+ self.assertEqual(q.sql(), "JOIN tablea ON condition = condition JOIN tableb ON condition = condition")
+
class TestSqlbuilderSqlite(Sqlbuilder, unittest.TestCase):
def setUp(self):