On 10/01/2012 04:48 PM, Michael Bayer wrote:
If I understand correctly, this isn't accurate. Your query needs the usage of
query.join(), and this usage is not related to whether or not you supply a
complete entity to select from.
I wasn't using explicit .join(), except an outerjoin on a one-to-one
relation with images table (which by default is lazyloaded). I thought
SQLA would figure it out itself based on foreign keys, as it usually
does. Maybe that's wrong, maybe I should be explicit, but so far it
worked (when entire instances of declarative_base were given to
session.query()).
I forgot to mention, and this could be the cause of perceived problems,
that I was listing columns of more than one model in the
session.query(). Maybe that confused it.
What happened was that the query returned a list of named tuples for
each of the rows returned by the database, while I was expecting only
one instance of the main model (see below).
I'm not sure what "won't automatically process inner joins" means, does that
mean, you get an error message, or you're forced to call .join() as opposed to some other
system of joining two entites, or what.
I mean the cartesian cross-product in queries with many-to-many
relations. SQLA would "automatically" recognize the queried models and
construct the model instances and their relationships properly.
E.g. if I query for single model that has X related in a many-to-many
fashion, the query would return X number of rows, like with
.joinedload(), but SQLA would return only one instance of the model, and
its related property filled with a list of X instances of that model,
i.e it would automatically process the joins and create a relationship
tree in the session.
I hope I'm making sense here. :)
I guess I should make a minimal example case for this, and will do as
time permits.
--
.oO V Oo.
Work Hard,
Increase Production,
Prevent Accidents,
and
Be Happy! ;)
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.