its because your post mapper is using joined table inheritance, i.e.
joining text_items to posts. so the primary key of "text_items JOIN
posts on text_items.id==posts.id" is a composite of "text_items.id,
posts.id". So.....it considers the primary key of Post id #1 to be
this:
m.get(1,1)
or in 0.2, like:
m.get((1,1))
there is the notion that the primary key of such a join should only
use the single column from "text_items", since the primary key of
"posts" is also the foreign key thats being related to text_items;
its redundant and thats why you intuitively used only one primary key
value in your get() (and also why get_by works).
but it seems like Join object is going to have to analyze the join
condition to see if there is literally a
"table1.primary_key==table2.foreign_and_primary_key" condition since
there are other join conditions with two tables like this where this
rule wouldnt apply. that will require some elaborate logic.....so i
think you have to stick with the "dual id" thing for the near term.
On May 17, 2006, at 5:41 PM, Marty McFly wrote:
Hi everybody, here's a small script using mapper inheritance that
fails on my machine (SQLAlchemy 0.1.7, Python 2.4.2). The following
line at the end of the script below causes an error:
firstTry = Post.mapper.get(1)
Whereas the next line works fine
secondTry = Post.mapper.get_by(id=1)
Is it a bug or a mistake on my part? Here's the sample script in
case anybody wants to test the whole thing:
----------------------------------------------------
from sqlalchemy import *
engine = create_engine('mysql',
{
'db':'sqlalchemy',
'user':'myself',
'passwd':'mypassword',
'host':'127.0.0.1'
},
)
text_items = Table('text_items', engine,
Column('id', Integer, primary_key=True),
Column('text', String)
)
posts = Table('posts', engine,
Column('id', Integer, ForeignKey("text_items.id"),
primary_key=True),
Column('headline', String)
)
text_items.create()
posts.create()
class TextItem(object):
pass
class Post(TextItem):
pass
TextItem.mapper = mapper(TextItem, text_items)
Post.mapper = mapper(Post, posts,
inherits=TextItem.mapper,
)
post = Post()
post.text = "it pretty much always means no"
post.headline = "maybe"
objectstore.commit()
firstTry = Post.mapper.get(1)
secondTry = Post.mapper.get_by(id=1)
-------------------------------------------
Here's the traceback from the "first try":
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "build\bdist.win32\egg\sqlalchemy\mapping\mapper.py", line
251, in get
File "build\bdist.win32\egg\sqlalchemy\mapping\query.py", line
43, in get
File "build\bdist.win32\egg\sqlalchemy\mapping\query.py", line
201, in _get
IndexError: tuple index out of range
The "second try" works fine.
Thanks and cheers, Martin
Schnell und einfach ohne Anschlusswechsel zur Lycos DSL Flatrate
wechseln und 3 Monate kostenlos ab effektiven 5,21 EUR pro Monat im
ersten Jahr surfen.
http://www.lycos.de/startseite/online/dsl/index.html?
prod=DSL&trackingID=email_footertxt
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users