On Jul 13, 2007, at 2:26 AM, Yves-Eric wrote:

>
> Maybe actually asking some questions would have helped getting
> replies :-)
>

sorry, i totally did not see this message on july 2 ?

> Is this not a bug? I may be wrong, but I would consider this a pretty
> serious bug, as it does not raise an error, but silently returns the
> wrong object, which could lead to serious data corruption...
>
>

there is a bug here.  theres a commit in r2891 which fixes it, at  
least for your case.  a further fix will need to be applied pending  
ticket #185 for deeper inheritance situations.

there are three ways to work around the bug right now.

1. the "normal" way, which is why most people dont have this  
problem.   create the schema with a shared primary key.  this is how  
table inheritance is usually done.

person_table = Table("persons", __meta__,
         Column("id", Integer, primary_key=True),
         Column("name", String(80)),
         )

employee_table = Table("employees", __meta__,
         Column("id", Integer, ForeignKey("persons.id"),  
primary_key=True),
         Column("salary", Integer),
         )

2. otherwise, you have two primary key columns here:  persons.id and  
employees.id.  they are not synonymous with each other;  therefore  
your PK is composite of both of those, for the Employee class.  so  
the two ways to work around the bug are:

        a. specify the primary key to the mapper explicitly:

person_mapper = mapper(Person, person_table)
mapper(Employee, employee_table, inherits=person_mapper, primary_key= 
[person_table.c.id, employee_table.c.id])

When doing this, you have a composite PK on employee.  test code  
looks like:

alice1 = query.get([1,2])
bob = query.get([2,3])
alice2 = query.get([1,2])

        b. name the columns differently, since the bug is a name collision  
thats occuring (rev 2891 removes this name collision by representing  
a composite PK as a non-keyed set)

person_table = Table("persons", __meta__,
         Column("id", Integer, primary_key=True),
         Column("name", String(80)),
         )

employee_table = Table("employees", __meta__,
         Column("employee_id", Integer, primary_key=True),
         Column("salary", Integer),
         Column("person_id", Integer, ForeignKey("persons.id")),
         )

again, you need to use composite PKs for access:

alice1 = query.get([1,2])
bob = query.get([2,3])
alice2 = query.get([1,2])



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to