On Feb 3, 2011, at 11:58 AM, neurino wrote:

> That is great!
> 
> Just for eventual followers I fix imports:
> 
>    from sqlalchemy.orm import object_mapper
>    from sqlalchemy.orm.attributes import instance_state
> 
>    m = object_mapper(item_to_be_deleted)
>    for rec in m.cascade_iterator("delete",
> instance_state(item_to_be_deleted)):
>       obj = rec[0]
>       print "item will be deleted !", obj
> 
> Anyway there's some way to stop recursiveness after a given level (or
> just 1)?
> 
> That's because for me deleting one ctrl_unit means deleting hundreds
> of `Acquisition`s with thousands of `Data` each that means a **lot**
> of queries and I could assume the user is smart enough to know that if
> he deletes an Acquisition he deletes its data too...
> 
> I'm looking at cascade_iterator def source, I could hack that end
> enclose directly in my code, the halt_on parameter is unused, as far
> as I understand.
> 
> Thanks for your support

halt_on works, you use that, its a callable.


> neurino
> 
> 
> 
> 
> On Feb 3, 5:19 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
>> you could use the mapper's "cascade" function
>> 
>> from sqlalchemy.orm import object_mapper, instance_state
>> m = object_mapper(item_to_be_deleted)
>> for rec in m.cascade_iterator("delete", instance_state(item_to_be_deleted)):
>>    obj = rec[0]
>>    print "item will be deleted !", obj
>> 
>> On Feb 3, 2011, at 6:15 AM, neurino wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> Can I show the user a warning like:
>> 
>>>    "if you delete this item also [list of other items] will be
>>> removed"
>> 
>>> whichever is the item?
>> 
>>> I was using something like this:
>> 
>>>    import inspect
>>>    def get_items(item_to_be_deleted):
>>>        """get_items(item_to_be_deleted) -> [(child_item_name,
>>> number_of_child_items)]"""
>>>        return [(name, len(inst)) for (name, inst) in
>>>            inspect.getmembers(item_to_be_deleted)
>>>            if isinstance(inst, orm.collections.InstrumentedList)]
>> 
>>> and it worked until all relationships had cascade delete but now I
>>> have one without it and it shows in the list too while it shouldn't...
>> 
>>> Any tips?
>> 
>>> Thank you for your support
>>> neurino
>> 
>>> --
>>> 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 
>>> athttp://groups.google.com/group/sqlalchemy?hl=en.
> 
> -- 
> 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.
> 

-- 
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