On Apr 11, 2007, at 4:50 AM, Gaetan de Menten wrote:
> looks better, is shorter and is more readable than: > > Query('Address', instance=someuser, attr_name='addresses') Ive no problem with the classmethod being present and i dont want people using Query's constructor in general. > And second, I think it could be quite confusing for a user. Imagine > that Query(A).from_attr(inst, 'rel') could return instances of B (or > whatever class is attached to the relation)... Probably not what you'd > expect. that should raise an exception, if the given instance/relationship pair does not match the query's main entity. theres also the possibility that we could "add" the entity in using add_entity() but lets not go there for now. generally, any method on Query which generates a SQL clause is potentially useful in a generative sense...since any SQL clause is always useful as part of a larger SQL clause. > And by the way, from_attr doesn't sound like a generative method, so > if you want it, what about "filter_from_attr", or something similar? what it really is, is like "with_parent" (to paraphrase an SQLElixer term). using the standard User->Address relation, I say session.query(Address).with_parent(someuser, relation='addresses'). additionally, the "addresses" string which marks the name of the attribute on User that points to Address should be optional, if it can be automatically determined from the existing relationships between User and Address. (if there is *any* ambiguity though, like two relations on user that point to address, it should raise an error). So people can say (as I myself find myself wanting to say), session.query(Address).with_parent(someuser).filter_by (email='[EMAIL PROTECTED]'). right now I have mentioned the "trick" that uses backrefs to get the same effect, this is more convenient since it isnt forcing a backref to exist just to generate a certain query. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---