Hi

I'd like to use an associationproxy for a simple many-to-one relationship:

class Child(Base):
    __tablename__ = 'child'
    id = Column(Integer, primary_key=True)
    name = Column(Unicode)

class Parent(Base):
    __tablename__ = 'parent'
    id = Column(Integer, primary_key=True)
    child_id = Column(Integer, ForeignKey('child.id')
    child_ = relationship(Child)
    child = association_proxy('child_', 'name', creator=)

Now 'child' is a read-only, dictionary-like table. I never want to insert
new rows in this table.

So I actually pass the following "creator" to the association_proxy
constructor:

def creator(name):
    return Session.query(Child).filter_by(name=name).first()

That does the job for "create". But I cannot find a solution for "update".
On update I'd like to replace the current Child object in the Parent object
by a new Child object read from the 'child' table.

Using a specific setter (in a getset_factory) does not work for me, as the
setter receives the Child object (and the value), not the Parent object –
I'd need a ref to the Parent object to be able to change its Child object
in child_.

Maybe I'm doing it all wrong and using an associationproxy is not the way
to go for that case.

Thanks for any suggestion.


-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemo...@camptocamp.com
http://www.camptocamp.com

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to