Re: [Modeling-users] slooow delete
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2005-03-18 18:01:05
|
John Lenton <jl...@gm...> wrote: > Thank you very much for your reply. Just one small doubt > remains: > > > On Fri, 18 Mar 2005 12:18:57 +0100, Sebastien Bigaret > <sbi...@us...> wrote: > > > > And, if you do this: just make sure that > > > > - either task.getMeal().isFault() == true > > > > - or that, in case it is not, that > > task.getMeal().getTasks().isFault()==true > > > > In this last case, if it is false, then you can do the > > meal.addToTasks(task) without any overhead, since this > indicate > > that > > the fetch has already be done. > > is there any case where the last line would return false, > instead of > raising an AttributeError? Good question ;) Here are the details First situation: you have a newly created object ; in this case, meal.getTasks() will be a real python list (actually a list or a tuple), assigned by the constructor, and you'll get an AttributeError. Second situation: the object has been fetched by the framework. In this case, any attribute corresponding to a tomany relationship is initialized with the so-called <<to-many fault>> object, responsible for lazily initializing the list when appropriate. If you're curious, you'll have a look at FaultHandler.AccessArrayFaultHandler, which is the corresponding class proxying the underlying list. So, in this case, you'll get a true or false answer when asking meal.getTasks().isFault(). As a conclusion, you're right, you have to check for AttributeError as well and your code will handle all possible situations. -- Sébastien. -- Sébastien. |