Hi :)
I have three tables:
1)
t_version = sa.Table("versions", meta.metadata,
sa.Column("id", sa.types.Integer(), primary_key=True,
autoincrement=True),
sa.Column("version", mysql.MSChar(length=100,
collation='utf8_polish_ci'), nullable=False, unique=True)
)
class Version(object):
pass
orm.mapper(Version, t_version)
2)
t_type = sa.Table("types",
meta.metadata,
sa.Column("id", sa.types.Integer(), primary_key=True,
autoincrement=True),
sa.Column("name", mysql.MSChar(length=100,
collation='utf8_polish_ci'), nullable=False, unique=True),
)
class Type(object):
pass
orm.mapper(Type, t_type, properties = {
'engine' : orm.relation(Engine, uselist=False,
backref='Type_Engine')
})
3)
t_engine = sa.Table("engines", meta.metadata,
sa.Column("id", sa.types.Integer(), primary_key=True,
autoincrement=True),
sa.Column("min_version_id", sa.types.Integer(), sa.ForeignKey
("versions.id"), nullable=False),
sa.Column("max_version_id", sa.types.Integer(), sa.ForeignKey
("versions.id"), nullable=False),
sa.Column("type_id", sa.types.Integer(), sa.ForeignKey
("types.id"), nullable=False),
)
class Engine(object):
pass
orm.mapper(Engine, t_engine, properties = {
'type' : orm.relation(Type, uselist=False, backref='Engine_Type'),
'min_version' : orm.relation(Version,
primaryjoin=t_engine.c.min_version_id==t_version.c.id),
'max_version' : orm.relation(Version,
primaryjoin=t_engine.c.max_version_id==t_version.c.id)
})
My problem is how to make query equal this SQL instruction "select
e.id, e.type_id, tv.version as min_version, tv2.version as max_version
from engines e join versions tv on(e.min_version_id=tv.id) join
versions tv2 on(e.max_version_id=tv2.id) where '7.0.1.32' between
tv.version and tv2.version;"
I've tried to do something like that:
engine = meta.Session.query(Engine).outerjoin(Version).filter(between
(request.POST['version'], Engine.min_version.version,
Engine.max_version.version)).all()
but I've got:
ArgumentError: Can't determine join between 'engines' and 'versions';
tables have more than one foreign key constraint relationship between
them. Please specify the 'onclause' of this join explicitly.
Thanks in advance for help.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---