What I still don't get is why _my_ flush changes the result. The
structure of my controller is:

a = Article()
sometopic.articles.append(a)
DBSession.add(a)
DBSession.flush()
[end of controller]

As far as I understand, Turbogears automatically flushes and commits
with its transaction manager. Why does my additional flush just before
the automatic flush change the result?

On 03/01/11 20:51, Diez Roggisch wrote:
>> If I understand the docs correctly, Turbogears commits my transaction
>> automatically if I use the ORM in my controller.
>>
>> This is used in this example: 
>> http://turbogears.org/2.1/docs/main/Wiki20/wiki20.html
>>
>>    @expose("wiki20.templates.edit")
>>    def notfound(self, pagename):
>>        page = Page(pagename=pagename, data="")
>>        DBSession.add(page)
>>        return dict(wikipage=page)
>>
>> Which works.
>>
>> However, if I have a model with references to another one (here with
>> elixir),
>>
>> class Article(Entity):
>>      contents = Field(Text(convert_unicode=True))
>>      topic = ManyToOne('Topic', inverse='articles')
>>
>> it stops working.
>> After creating an a=Article() and using sometopic.articles.append(a),
>> I have to call DBSession.flush(). Otherwise, the topic is saved as
>> None and sometopic.articles does not grow.
>>
>> It would be nice to understand why.
>>
> 
> It's a leaky abstraction. The problem is, that your code doesn't trigger the 
> actual insert. Then, you try to access the ID of the object - but that isn't 
> known at that point, due to the pending insert.
> 
> The flush forces the inserts, and subsequent updates of the instances.
> 
> IMHO SA and Elixir are to clever here for their own good, but we didn't find 
> a way to prevent this either.
> 
> Diez
> ___________________________________________________________
> Neu: WEB.DE De-Mail - Einfach wie E-Mail, sicher wie ein Brief!  
> Jetzt De-Mail-Adresse reservieren: https://produkte.web.de/go/demail02
> 

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en.

Reply via email to