sbrunner/c2c.sqlalchemy.rest — pull request #5 by asaunier (2013-10-23 18:12:55+00:00)
Title: Add possibility to retrieve related objects for read_many and read_one

Example of usage:

* in ``rest.py``:

```
tag_children = {
'childrenTags': 'tags'
}
tag = REST(DBSession, Tag, children=tag_children)
```

* in ``models.py``:

```
class Tag(GeoInterface, Base):
__tablename__ = 'tag'
__table_args__ = (
UniqueConstraint('name'),
{"schema": 'tagging'}
)
__acl__ = [
(Allow, 'admin', ALL_PERMISSIONS),
(Allow, 'editor', ('view', 'edit', 'new', 'delete')),
(Allow, Everyone, ('view')),
]
id = Column(types.Integer, primary_key=True)
name = Column(types.Unicode(200), nullable=False)
active = Column(types.Boolean, default=True)
l10n = relationship("TagL10n", backref="tag")
childrenTags = relationship("Tag",
secondary=tag_tag,
primaryjoin=id==tag_tag.c.tag_id1,
secondaryjoin=id==tag_tag.c.tag_id2,
order_by=name, backref="parentTags")
```

Will show something like
```
{
"active": false,
"tags": [{
"active": true,
"name": "Artenschutz",
"id": 31
}, {
"active": false,
"name": "Auenlandschaft",
"id": 39
}, {
"active": false,
"name": "Naturschutz",
"id": 58
}, {
"active": false,
"name": "Pioniervegetation",
"id": 71
}],
"name": "Naturschutz",
"id": 58
}
```