Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-28 Thread mike bayer
I've changed the assertions to all expect "3" items since assertions should illustrate what's expected to happen (this again communicates to me what the problem is). Applying expire() to all three (plus reassignment in the first case) allows them all to work. If you don't expire the relations

Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-28 Thread Colton Allen
from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() atob = Table( 'atob', Base.metadata, Column('aid', ForeignKey('a.id'), primary_key=True), Column('bid', ForeignKey('b.id'), primary_key=True) ) cla

Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-28 Thread mike bayer
here we are, please complete and return, thanks from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() atob = Table( 'atob', Base.metadata, Column('aid', ForeignKey('a.id'), primary_key=True), Column('b

Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-28 Thread mike bayer
On 10/28/2016 09:13 AM, Colton Allen wrote: Okay I see. That does remove the error. But I am having trouble saving the relationship. Check the example code. It is much clearer than I am. I can't tell you why the code works or doesn't, at this level I need to run it. I will re-assemble

Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-28 Thread Colton Allen
Okay I see. That does remove the error. But I am having trouble saving the relationship. Check the example code. It is much clearer than I am. If I query a new set of items or specify an item model instance it will save perfectly. But all of the instances in the instrumented list will not

Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-27 Thread mike bayer
you'd say: session.expire(model, ["items"]) On 10/27/2016 04:47 PM, Colton Allen wrote: Sorry I must have combined multiple attempts into one example. When you say expire the relationship, what do you mean? On Thursday, October 27, 2016 at 4:30:36 PM UTC-4, Mike Bayer wrote: Hello -

Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-27 Thread Colton Allen
Sorry I must have combined multiple attempts into one example. When you say expire the relationship, what do you mean? On Thursday, October 27, 2016 at 4:30:36 PM UTC-4, Mike Bayer wrote: > > Hello - > > > I've rebuilt your fragment into a full example in order to determine > what the behavio

Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-27 Thread mike bayer
Hello - I've rebuilt your fragment into a full example in order to determine what the behavior is here, as make_transient() has no defined behavior for loaded relationships. Your error does not reproduce with your code fragment as given, because you are setting the list of items to itself,

[sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-27 Thread Colton Allen
I want to create a new row with all of the same data. However, (using make_transient) the many-to-many "items" relationship doesn't carry over to the new model. When I manually set the items I recieve a "StaleDataError". How can I insert the many-to-many relationships so this does not happen?