Re: [sqlalchemy] Updating a one-to-many relationship

2013-08-14 Thread Simon King
I think you may be confused about the relationship properties you have here. As far as I can tell, a Creator can have many companies, but each Company has only one creator, correct? So Company.creator should only ever be an instance of Creator (or None), whereas Creator.companies should be a list.

Re: [sqlalchemy] Cross-schema foreign keys reflection

2013-08-14 Thread Jason
On Tuesday, August 13, 2013 7:43:54 PM UTC-4, Michael Bayer wrote: cross-schema reflection is supported on PG but has caveats, see http://docs.sqlalchemy.org/en/rel_0_8/dialects/postgresql.html#remote-cross-schema-table-introspectionfor a discussion of recommended usage patterns.

[sqlalchemy] many-to-one relationship with intermediate table non equijoin

2013-08-14 Thread avdd
Hello all Tried for hours to figure out the various relationship() options with no luck. Consider: class Enrolment(base): __tablename__ = 'enrolment' person_id = Column(String, primary_key=True) group_id= Column(String, primary_key=True) enrol_date = Column(Date,

Re: [sqlalchemy] many-to-one relationship with intermediate table non equijoin

2013-08-14 Thread Michael Bayer
create a non primary mapper to a select() that's against the Enrolment table joined to RosterLine (i.e. mapper(myselect.alias(), non_primary=True), then construct a relationship() to that mapper (viewonly=True of course). at some point I should add an example of this technique, it's just the

Re: [sqlalchemy] Updating a one-to-many relationship

2013-08-14 Thread csdrane
Simon, your idea about putting together a script is a good one. Please see the attached. I think all these errors are related but I'm scratching my head about what the problem is. The reason I use self.creator[0] versus self.creator is for aesthetics. And, to your point about creator not

[sqlalchemy] Under what circumstances will a `inspect(myobject).attrs.myattribute.history` be a sequence of more than one item ?

2013-08-14 Thread Jonathan Vanasco
As previously discussed, i'm using an object's history to log changes to the database within an application. http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html?highlight=history#sqlalchemy.orm.attributes.History Each tuple member is an iterable sequence I'm trying to figure out when I

[sqlalchemy] TypeDecorator to store bool as ENUM('N', 'Y')?

2013-08-14 Thread Jeff Dairiki
I'm working with an existing MySQL schema that has lots of columns of type ENUM('N', 'Y'). I'd like to deal with them as real booleans on the python side. I have a simple TypeDecorator which almost works (I think): class YNBoolean(sqlalchemy.types.TypeDecorator): impl =

[sqlalchemy] Re: many-to-one relationship with intermediate table non equijoin

2013-08-14 Thread avdd
Thanks for the quick response! After much fiddling I got it working using alias(), foreign() and corresponding_column(). It seems to get the right results. Is this the simplest, right approach? joined = Enrolment.__table__.join(RosterLine,

[sqlalchemy] how to tell which columns are deferred in orm ?

2013-08-14 Thread Jonathan Vanasco
i'm trying to generate a list of non-deffered columns from an object referencing this example: class Book(Base): __tablename__ = 'book' book_id = Column(Integer, primary_key=True) title = Column(String(200), nullable=False) summary = Column(String(2000))

[sqlalchemy] Re: DeferredReflection and mapper

2013-08-14 Thread Lukasz Szybalski
On Wednesday, August 14, 2013 12:10:12 AM UTC-5, Lukasz Szybalski wrote: Hello, How do I go from class like defeinition to below with mapper. The docs in 0.8 say I can use: from sqlalchemy.ext.declarative import DeferredReflectionBase = declarative_base() class

Re: [sqlalchemy] Under what circumstances will a `inspect(myobject).attrs.myattribute.history` be a sequence of more than one item ?

2013-08-14 Thread Michael Bayer
yes it will always be one element for a scalar reference, a collection for collections. the ORM internally treats everything like a collection, kind of another artifact that probably wouldnt have been the case if this API were written for end-users originally... On Aug 14, 2013, at 9:20 PM,