zzzeek/sqlalchemy — pull request #86 by yelite (2014-05-07 15:57:48+00:00)
Title: add reflective parameter to AssociationProxy

When `reflective` is set to ``True`` the object which owns this proxy will be passed to `creator`. For list and set collections, the `creator` will be called with object and value. For dict types, three arguments are passed: object, key and value.

My problem when using `AssociationProxy`:
```python
class PostMeta(db.Model):
author_id = db.Column(db.Integer,
db.ForeignKey(User.id, ondelete='CASCADE'),
nullable=False)
tag_entries = db.relationship('Tag', secondary='tags_to_posts', collection_class=set,
backref=db.backref('posts', lazy='dynamic'))
tags = association_proxy('tag_entries', 'name')

class Tag(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode(25), nullable=False)
user_id = db.Column(db.Integer,
db.ForeignKey(User.id, ondelete='CASCADE'),
nullable=False)
__table_args__ = (
UniqueConstraint('name', 'user_id'),
)
```

When a new tag is going to be added to `PostMeta`, such like `p.tags.add('a new tag')`, I cannot find a way to create the new tag if `creator` only knows the new tag's name. In this case, it seems reasonable to pass `p` to `creator`, so `creator` can get `user_id` from `p.author_id`.