from sqlobject import *
from sqlobject.inheritance import InheritableSQLObject

__connection__ = "sqlite:/:memory:?debug=t"

class Versionable(InheritableSQLObject):
   version = StringCol()

class Task(Versionable):
   name = StringCol()
   task_list = ForeignKey("TaskList")

class TaskList(Versionable):
   name = StringCol()
   tasks = MultipleJoin("Task")
   category = ForeignKey("Category")

class Category(SQLObject):
   tag = StringCol()
   tasklists = MultipleJoin("TaskList")

#class Version(SQLObject):
#    versions = MultipleJoin("Versionable")


Versionable.createTable()
Task.createTable()
TaskList.createTable()
Category.createTable()
#Version.createTable()

cat = Category(tag="important")
tl = TaskList(name="tasks", version = 1, category = cat)
task1 = Task(name="take out trash", task_list = tl, version = 1)
task2 = Task(name="bathe cat", task_list = tl, version = 1)
task3 = Task(name="bandage wounds", task_list = tl, version = 1)

assert len(list(Task.select(AND(LIKE(Task.q.name, '%e%'),
Task.q.task_listID == tl.id, TaskList.q.categoryID == cat.id)))) == 3


------------------
Here's the query:
25/QueryR  :  SELECT versionable.id, versionable.version,
versionable.child_name FROM versionable, task, task_list WHERE
(((((task.name LIKE ('%e%')) AND (((task.task_list_id) = (1)) AND
((task_list.category_id) = (1)))) AND ((versionable.child_name) =
('Task'))) AND ((task.id) = (versionable.id))) AND ((task_list.id) =
(versionable.id)))


Of course it is wrong, because both tables are joined to versionable at
once, so there will never be any results.



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to