here's what i did and it seems to work:
class _Empty: pass
class Base4Association(..): #the base for assoc_objects
...
class MyCollection( list):
factory = None
def append( me, obj =_Empty, **kwargs):
if obj is _Empty: #marker for notset; else just use it
obj = me.factory( **kwargs) #create it from kwargs
list.append( me, obj)
return obj
@classmethod
def myCollectionFactory( klas):
m = Base4Association.MyCollection()
m.factory = klas
return m
...
def append( self, *args, **kwargs):
item = self._data_appender( *args,**kwargs)
#private __setrecord; was before _data_appender ????
self._InstrumentedList__setrecord( item)
sqlalchemy.orm.attributes.InstrumentedList.append = append
...
themapper.add_property( name,
sqlalchemy.relation(
actual_assoc_klas,
lazy= False, cascade= "all, delete-orphan",
uselist= True,
collection_class= actual_assoc_klas.myCollectionFactory
) )
> seems this is the month of the many2many relations ;-)
>
> why is a the whole assoc.proxy + _AssocList needed?
>
> Can't one do just with overloading/replaceing the
> InstrumentedList's append() ? or something of sorts. i know it
> might be messier, but with proper hooks it will be
> shorter/faster/easier/...
>
> in my case, i want any kwargs passed to append() to trigger
> creating proper assoc_obj off them, and using that one.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---