On Jun 4, 2012, at 11:08 AM, Antonio Beamud Montero wrote:

> El 04/06/12 16:37, Michael Bayer escribió:
>> On Jun 1, 2012, at 12:30 PM, Antonio Beamud Montero wrote:
>> 
>>> El 01/06/12 16:59, Michael Bayer escribió:
>>>> @appender needs to be a method that just accepts a mapped object to be 
>>>> added to the collection.   then, @internally_instrumented is needed to 
>>>> prevent the collections system from placing additional insturmentation on 
>>>> standard methods like __setitem__.   Also building custom dictionary 
>>>> collections is very difficult in any case (for me as well) so you were 
>>>> close, and that's pretty good !
>>>> 
>>> Only one more question.. Querying for example the ULine object, always give 
>>> me the permissions for all objects.. Exists any way to filter that 
>>> permissions by the User object I filter in the query, i.e. something like:
>>> 
>>>   objs = 
>>> session.query(ULine).join(PermissionAssoc).join(Permission).join(User).filter(User.username
>>>  == u'kratos').all()
>>>   print objs[0].permissions
>>> ----
>>>   MyMappedCollection({u'read': [<__main__.Permission object at 
>>> 0xa04442c>,<__main__.Permission object at 0xa04454c>]})
>>> ----
>> haven't looked at your example again but you'd work it out in SQL first to 
>> figure out the query you want, then convert to the ORM.  Is the issue that 
>> you don't know what the SQL is, or just how to get the Query to produce it ?
> 
> The query is easy, my problem is with the property 'permissions', associated 
> to a object. The definition in the PermissionAssoc is:
> 
> permissions = orm.relationship(Permission,
>                                backref='association',
>                                lazy=False,
>                                collection_class=MyMappedCollection)
> 
> But I don't know how to configure this relationship to filter by a user (I 
> don't know if it's possible). Like a dynamic relationship (to not query 
> always all the permissions for all user associated to this object).

if the relationship is not dynamic, you need to use it in a larger query and 
filter there:

query(PermissionAssoc).join(PermissionAssoc.permission).join(Permission.user).filter(User.something==something)

if you want an attribute to do this, then you'd use a @property or method on 
PermissionAssoc, get the session from object_session(self).

-- 
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.

Reply via email to