Re: [flask] Re: How do you guys solve reference problems with sqlalchemy?
- From:
- Peter Ward
- Date:
- 2011-09-18 @ 06:21
Why not do everything in A and B, and then commit together?
I think you’re saying your problem is that SQLAlchemy doesn’t give you the
ID until you have committed— to which my response is, why do you need the
ID?
If you have a relationship between them, you should be able to say
>>> a.my_b = b
instead of
>>> a.my_b_id = b.id
If this doesn’t work for you, perhaps you can provide a minimal example of
the problem?
On 18 September 2011 09:02, Italo Maia <italo.maia@gmail.com> wrote:
> I would like to rollback everything in case something went wrong. I believe
> my problem is I had to commit twice in order to have the id. How can I do it
> in a more...lazy way?
>
>
> 2011/9/17 Italo Maia <italo.maia@gmail.com>
>
>> I have a model A that references a Model B, so, I have to save B before
>> saving A. But, if I get a error after saving A, how should I undo what I did
>> in A and B if I did commit after saving B?
>>
>> --
>> "A arrogância é a arma dos fracos."
>>
>> ===========================
>> Italo Moreira Campelo Maia
>> Bacharel em Ciência da Computação - UECE
>> Desenvolvedor WEB e Desktop (Java, Python, Lua)
>> Coordenador do Pug-CE
>> -----------------------------------------------------
>> http://www.italomaia.com/
>> http://twitter.com/italomaia/
>> http://eusouolobomau.blogspot.com/
>> -----------------------------------------------------
>> Turtle Linux 9.10 - http://tiny.cc/blogturtle910
>> Turtle Linux 10.10 - http://bit.ly/cEw4ET
>> ===========================
>>
>
>
>
> --
> "A arrogância é a arma dos fracos."
>
> ===========================
> Italo Moreira Campelo Maia
> Bacharel em Ciência da Computação - UECE
> Desenvolvedor WEB e Desktop (Java, Python, Lua)
> Coordenador do Pug-CE
> -----------------------------------------------------
> http://www.italomaia.com/
> http://twitter.com/italomaia/
> http://eusouolobomau.blogspot.com/
> -----------------------------------------------------
> Turtle Linux 9.10 - http://tiny.cc/blogturtle910
> Turtle Linux 10.10 - http://bit.ly/cEw4ET
> ===========================
>
--
Peter Ward
http://flowblok.id.au/
BIT III, Sydney University