-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Having a problem with with_alias
#57
Comments
I managed to narrow down the least difference between the two codes that messes the query. This will work: db.define_table(
'cargo',
Field('titulo', type="string")
)
db.define_table(
'cargo_similar',
Field('cargo_id1', type=db.cargo),
Field('cargo_id2', type=db.cargo)
)
db.cargo.with_alias("start")
db.cargo.with_alias("end")
db.cargo_similar.with_alias("hop")
hop_join = (db.start.id == db.hop.cargo_id1) & (db.end.id == db.hop.cargo_id2)
print db(hop_join)._select(db.start.titulo, db.end.titulo) This won't: from pydal import *
db = DAL('mysql+mysqldb://root:@localhost:3306/conline', migrate=False)
db.define_table(
'cargo',
Field('cargo_id', type='id'),
Field('titulo', type="string")
)
db.define_table(
'cargo_similar',
Field('cargo_similar_id', type='id'),
Field('cargo_id1', type=db.cargo),
Field('cargo_id2', type=db.cargo)
)
db.cargo.with_alias("start")
db.cargo.with_alias("end")
db.cargo_similar.with_alias("hop")
hop_join = (db.start.id == db.hop.cargo_id1) & (db.end.id == db.hop.cargo_id2)
print db(hop_join)._select(db.start.titulo, db.end.titulo) It seems that introducing custom id fields messes something about the query generation. |
Also, if I use the name of the custom field it seems to work: hop_join = (db.start.cargo_id == db.hop.cargo_id1) & (db.end.cargo_id == db.hop.cargo_id2) |
At pydal level you have defined cargo_id1/cargo_id2 as FK for cargo.id |
@rcalsaverini @ilvalle may I close this? |
This is indeed a PyDAL bug and will be fixed by PR #433. |
Hi there. I'm trying to use pydal with an existing set of tables on my database and I'm hitting a wall here about how to deal with two rows of the same table appearing in the same query.
First a working example. Imagine I have two tables representing a directed graph:
Than I want the simplest query, just to print the names of the nodes that are connected by an edge:
The obtained query is:
Which is exactly what I want. This works perfectly.
But for some reason, when I try this with my real database this doesn't work at all:
The sql generated is:
which fails to use the alias and ends up not producing the inner join I want (it actually returns all pairs of
position_from
andposition_to
regardless of whether there is ahop
connecting them or not.I can't spot the difference between the two codes except for the names of the tables and fields. What am I doing wrong?
Thanks for your time.
The text was updated successfully, but these errors were encountered: