[sqlalchemy] Self populating a new instance relationships, best practice

2011-10-04 Thread neurino
I have a mapped class with a one to many relationship to another class. My need is that when a parent class is added to session automatically it's populated with predefined children too. I used to hook to `after-insert` event but now I read it's not suitable for any Session.add (has it ever been

Re: [sqlalchemy] Self populating a new instance relationships, best practice

2011-10-04 Thread Michael Bayer
On Oct 4, 2011, at 8:21 AM, neurino wrote: I have a mapped class with a one to many relationship to another class. My need is that when a parent class is added to session automatically it's populated with predefined children too. I used to hook to `after-insert` event but now I read

Re: [sqlalchemy] Self populating a new instance relationships, best practice

2011-10-04 Thread neurino
Hi Michael, the reason is Parent does not know its children until another relationship is set (`id_str` in the code above). Consider this form validation part: if form.validate(): user_strat = form.bind(UserStratigraphy()) I cannot bind prior creating an instance and this is quite a common

Re: [sqlalchemy] Self populating a new instance relationships, best practice

2011-10-04 Thread Michael Bayer
On Oct 4, 2011, at 9:37 AM, neurino wrote: Hi Michael, the reason is Parent does not know its children until another relationship is set (`id_str` in the code above). Consider this form validation part: if form.validate(): user_strat = form.bind(UserStratigraphy()) I cannot