relationship() expects a class or a mapper instance, not a string. I got this error:
ArgumentError: relationship 'available_deals' expects a class or a mapper argument (received: <type 'str'>) On Nov 10, 4:46 pm, "Sergey V." <sergey.volob...@gmail.com> wrote: > > The twist is that I've spread out my tables and ORM classes across > > several files. I've tried to keep it so that I don't have circular > > dependencies. That means I've defined Merchant first, and then Deal > > later, in separate files > > To avoid problems with imports and dependencies you can pass strings > to the relationship function instead of the actual classes: > > mapper(Deal, deals, properties=dict( > merchant=relationship('Merchant', backref='deals'), > )) > > This greatly simplifies everything if you split your classes into > separate files. > > Regarding 'available_deals', 'deleted_deals' etc. - the approach with > properties is sub-optimal. Consider a merchant having thousands of > deals, only a few of which are available - the method would have to > fetch all those deals only to discard most of them. Also, that won't > work with eager loading. The optimal way would be to make SA to > generate a query like "SELECT ... FROM Deals WHERE ... AND deleted=1" > which would return only the records we're interested in. I'm sure it's > possible but I'll leave it to you to find it in SA docs :) When you > find it please post it here :) -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.