On Tuesday 19 December 2006 23:22, David Turner wrote:
> 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.

I don't consider this a bug in the strict sense of the word - you are abusing 
InheritableSQLObject. By inheriting from it, you make things essentially the 
same kind, but all you really want is them all to respond to a common 
interface. 

You should instead go for "common" inheritance, as it is shown in e.g. 
test_inheritance.py from sqlobject's tests:

class Super(SQLObject):

    name = StringCol(length=10)

class Sub(Super):

    name2 = StringCol(length=10)

def test_super():
    setupClass(Super)
    setupClass(Sub)
    s1 = Super(name='one')
    s2 = Super(name='two')
    s3 = Super.get(s1.id)
    assert s1 == s3

def test_sub():
    setupClass(Super)
    setupClass(Sub)
    s1 = Sub(name='one', name2='1')
    s2 = Sub(name='two', name2='2')
    s3 = Sub.get(s1.id)
    assert s1 == s3


Diez

-------------------------------------------------------------------------
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