Hello,
I have a problem with "order_by" on a many-to-many relationship (using
assign_mapper):
------------------------------
attachment_table = Table('attachments', meta,
Column('id', Integer, primary_key=True),
Column('file', Binary, nullable=False),
Column('name', Unicode(40), nullable=False),
Column('type', Unicode(30)),
Column('date', DateTime, default=datetime.now),
Column('size', Integer, nullable=False),
Column('description', Unicode(40)),
)
attachments_has_sites = Table('attachments_has_sites', meta,
Column('id_attachment', None, ForeignKey('attachments.id'),
primary_key=True),
Column('id_site', None, ForeignKey('sites.id'), primary_key=True),
)
class Attachment(object):
pass
attachment_mapper = assign_mapper(ctx, Attachment, attachment_table,
properties={
'file':deferred(attachment_table.c.file),
'sites':relation(Site, backref="attachments",
secondary=attachments_has_sites, cascade="save-update"),
},
order_by=attachment_table.c.name,
)
------------------------------
So I have a Site object where I can ask for it's attachments:
s = model.Site.get(1)
attachment_list = s.attachments
But it fires the following QUERY:
SELECT attachments.name AS attachments_name, attachments.description AS
attachments_description, attachments.date AS attachments_date,
attachments.type AS attachments_type, attachments.id AS attachments_id,
attachments.size AS attachments_size
FROM attachments, attachments_has_sites
WHERE %s = attachments_has_sites.id_site AND attachments.id =
attachments_has_sites.id_attachment ORDER BY
attachments_has_sites.id_attachment
the "ORDER BY" is computed against the weak table (secondary)
"attachments_has_sites".
Regards,
--
Alexandre CONRAD
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---