On Fri, May 16, 2008 at 4:54 PM, jason kirtland <[EMAIL PROTECTED]> wrote:
[..]
>>
>> Anyway, I think this is a bit non-intuitive.  What I propose instead
>> is that SA could automatically set the 'keyword' attribute of the Note
>> object as part of the process of assigning it to the mapped collection
>> dictionary.  This way the insert could look more like:
>>
>> item.notes['not-color'] = Note(value='blue')
>>
>> and behind the scenes SA would call:  <new Note>.keyword = 'not-color'
>>
>> Any thoughts on this?  Has anyone tried this in the past?
>
> MappedCollection doesn't currently have a mismatch guard on __setitem__
> (d[key] = val) or setdefault(), but easily could.  There *is* a guard
> protecting against item.notes = {'not-color': Note('color', 'blue')}, so
> that machinery is available and applying it to the other setters is
> straightforward.
>
> Automatically setting the value for the attribute_ and column_mapped
> dict collections would be pretty convenient and DRY.  This is a great
> time to integrate that feature, if you want to try your hand at putting
> together a patch and tests.  If it's not too disruptive to existing
> users it could slide right in as a new feature of 0.5.

I would be more then happy to look into this (I already have), but I
think my skills aren't quite up to the challenge.  Could you point me
in the general direction?

On a related note, I think it would be good to make this behavior come
through a user customizable callback method that takes the index value
and the newly assigned class item as values.  This would allow users
to add more automatic behavior that may be needed.

For example I my current relationship is actually like this:

   'input_vars' : relation(Var, primaryjoin = and_(script_table.c.id
== var_table.c.script_id,

var_table.c.input_output_type == 0),

collection_class=column_mapped_collection(var_table.c.name)),

So I would want to not only set the name automatically based on the
key, but I would want to set the input_output_type to 0 in this case.
Something like this would be good.

def input_cb(key, item):
   item.name = key
   item.input_output_type = 0

'input_vars' : relation(Var, primaryjoin = and_(script_table.c.id ==
var_table.c.script_id,

var_table.c.input_output_type == 0),

collection_class=column_mapped_collection(var_table.c.name,
set_cb=input_cb)),

Any thoughts and/or pointers on how to implement this?

-Allen

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to