Re: [Sqlalchemy-tickets] [sqlalchemy] #2808: AssociationProxy should use keywords on create
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-08-22 15:11:28
|
#2808: AssociationProxy should use keywords on create
-------------------------------------------+-------------------------------
Reporter: schlamar | Owner: zzzeek
Type: enhancement | Status: new
Priority: medium | Milestone: 0.8.xx
Component: ext | Severity: minor - half an
Resolution: | hour
Progress State: needs questions answered | Keywords:
-------------------------------------------+-------------------------------
Comment (by zzzeek):
that's what "creator" is for:
{{{
#!python
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
name = Column(String(64))
keywords = association_proxy('user_keywords', 'keyword',
creator=lambda v: UserKeyword(keyword=v))
}}}
this can be generalized with your preferred style:
{{{
#!python
def my_association_proxy(src, target):
def create(value):
target_cls = prox.target_class
return target_cls(**{target: value})
prox = association_proxy(src, target, creator=create)
return prox
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
name = Column(String(64))
keywords = my_association_proxy('user_keywords', 'keyword')
}}}
it should be apparent why we can't just change
`_AssociationList._create()` here.
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2808#comment:6>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|