[sqlalchemy] Why don't dynamic_loader relations support order_by?
Hi! I'm replacing some relation()s by dynamic_loader()s and encountered the problem that the order_by parameter doesn't work anymore. Obviously dynamic_loader doesn't support it. Is this left out with a special purpose? I'd find it quite useful to have a default ordering for the related children instead of adding .order_by(Class.column) on each access. Maybe it's not easy to implement, but from a user perspective it might be nice to be able to use all relation() options in a dynamic_loader() (although I'd already be happy with order_by ;)). So it there a chance that dynamic_loader will be enhanced one day or is this limitation intended? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Tiny feature request (+patch): Adding __len__ to orm.query.Query
Hi! As I can also use several list operations on a Query instance (like access by index, slicing, ...) it might be a good idea to add __len__, so that I can use the pythonic len(query). The patch would be trivial (unless there are some internal issues that I don't know). Just add this method to the Query class: def __len__(self): return self.count() What do you think? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] How to do date calculations in a query and in relations?
Hi! I'm trying to filter my data by some date calculations. In detail, I want to filter out messages that have been marked as deleted more than 30 days ago. In a query I could do it like this: threshold = datetime.now() - datetime.timedelta(30) return Message.query().filter(Message.deleted threshold).all() But how can I do it in a relation() that returns all deleted messages? I'd have to calculate the threshold on every call to the relation or I'd have to create a query that will do the calculation in SQL. For both options I don't know how I could accomplish it. messages_deleted=relation( Message, primaryjoin=and_(conditions to create the relation, message_table.c.deleted ), ), Any ideas? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Using count on a relation without loading all related entities?
If you want to count the children of a parent entity you can do it like that: parent.children.count(Child.id) Generally, this is fine. But it loads all children into the session and then manually counts them. For large sets this will become very slow. Wouldn't it be smarter to do the count in the database, as it would be done with the following query? session.query(Child).filter(Parent.id==Child.parent_id).count(Child.id) Currently I have to implement a children_count() method in the parent to avoid loading all the children from the database. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Bug (?) in combined 1:n:1 + m:n relation mapping
On Oct 16, 7:42 pm, Michael Bayer [EMAIL PROTECTED] wrote: On Oct 16, 2007, at 1:30 PM, [EMAIL PROTECTED] wrote: Am I really supposed to save/flush/clear/query my objects to get the correct mappings? Or is this a bug? the advised pattern here is the association object pattern described in the docs: http://www.sqlalchemy.org/docs/04/ mappers.html#advdatamapping_relation_patterns_association Ah, great. Thank you for your advice! Using the association proxy http://www.sqlalchemy.org/docs/04/plugins.html#plugins_associationproxy I can also easily access the entities without explicitly using the association: u1 = User(test user 1) e1 = Event(test event 1) u1.events.append(e1) # association automatically created u2 = User(test user 2) e2 = Event(test event 2) p2 = Participation(user=u2, event=e2, status=42) # explicit creation of the association Modified code for classes and mappers: from sqlalchemy.ext.associationproxy import association_proxy class User(object): def __init__(self, name=None): self.name = name events = association_proxy('participations', 'event', creator=lambda e: Participation(event=e)) class Event(object): def __init__(self, title=None): self.title = title users = association_proxy('participations', 'user', creator=lambda u: Participation(user=u)) class Participation(object): def __init__(self, event=None, user=None, status=0): self.event = event self.user = user self.status = status mapper(User, user_table, properties=dict( participations=relation(Participation, backref='user'), ) ) mapper(Participation, participation_table, properties=dict( user=relation(User, backref='participations') ) ) mapper(Event, event_table, properties=dict( participations=relation(Participation, backref='event'), ) ) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Bug (?) in combined 1:n:1 + m:n relation mapping
On Oct 17, 12:21 pm, Thomas Wittek [EMAIL PROTECTED] wrote: mapper(Participation, participation_table, properties=dict( user=relation(User, backref='participations') ) ) Should be: mapper(Participation, participation_table) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---