Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Hipp
On 2/13/2014 11:45 AM, Michael Bayer wrote: So for children above you need to spell out primaryjoin completely which is primaryjoin=and_(Animal.sire_id == Animal.id_, Animal.dam_id == Animal.id). Thought I was on the right track but now getting the exception below. Here's the model: class

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Hipp
On 2/14/2014 11:50 AM, Michael Bayer wrote: On Feb 14, 2014, at 12:46 PM, Michael Hipp mich...@redmule.com wrote: On 2/13/2014 11:45 AM, Michael Bayer wrote: So for children above you need to spell out primaryjoin completely which is primaryjoin=and_(Animal.sire_id == Animal.id_

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Hipp
On 2/14/2014 1:51 PM, Michael Bayer wrote: right this is why reading the docs is better, those have been checked... remote side for m2o refers to the primary key, so: The docs says: '...directive is added known as remote_side, which is a Column or collection of Column objects that indicate

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Hipp
On 2/14/2014 2:34 PM, Michael Bayer wrote: A basic fact of a self referential relationship is that you're building a tree. The root of the tree has to be NULL and I'd advise against trying to work around that. Now if you wanted to in fact assign the object's own primary key to the foreign

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Hipp
On 2/14/2014 3:36 PM, Michael Bayer wrote: the django ORM would write an autogenerated primary key value to a foreign key column at the same time in a single INSERT? What magic might they have discovered there? (hint: i am sure they don't do that) Naw. If you recall I was supplying the pkey

[sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
I'm trying to do something like this: class Animal(Base): __tablename__ = 'animals' id_ = Column(Integer, primary_key=True) sire_id = Column(Integer, ForeignKey('animals.id_')) dam_id = Column(Integer, ForeignKey('animals.id_')) sire = relationship('Animal',

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
On 2/13/2014 11:06 AM, Josh Kuhn wrote: I think you need to use the remote_side argument for the children relationship, since it's the same table http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#adjacency-list-relationships Thanks. I'm just not sure how to specify it when there

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
On 2/13/2014 11:04 AM, Michael Bayer wrote: On Feb 13, 2014, at 11:53 AM, Michael Hipp mich...@redmule.com wrote: I don't see a first_owner relationship defined above, so the above example is not complete. The approach using foreign_keys is the correct approach to resolving ambiguity in join

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
On 2/13/2014 11:45 AM, Michael Bayer wrote: primaryjoin=and_(Animal.sire_id == Animal.id_, Animal.dam_id == Animal.id) Thank you. That works great. And thanks for the explanation. Michael -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To

[sqlalchemy] Using SQ with Django models

2014-02-01 Thread Michael Hipp
Hello, I have a database in PostgreSQL that is built and updated using Django 1.2 and I'd like to access it with SA. Are there any quick pointers you could offer to get me started on the best way to do that (e.g. duplicate Django's models.py in SA, use reflection, etc.)? The tables have a

[sqlalchemy] Returning a simple list?

2012-03-12 Thread Michael Hipp
Doing a simple query like this, I just want to get a list of the pkeys in the table: q = select([mytable.c.id,]) pkey_list = engine.execute(q).fetchall() What I get back looks like: [(1,), (2,)] But what I need is just: [1, 2] It's easy enough to make that happen in Python, but was

[sqlalchemy] engine.close() ?

2012-03-02 Thread Michael Hipp
Is there anything that should be done to close an engine just before application termination? I don't see a .close() method but there is a .dispose() method. Thanks, Michael -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group,

[sqlalchemy] ORM __eq__

2012-02-15 Thread Michael Hipp
a==b come out True? Thanks, Michael Hipp -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com

[sqlalchemy] A long-lived ORM object

2012-02-08 Thread Michael Hipp
I have an ORM object that gets loaded once during program run and never changes. sess = Session() unchanging = sess.query(Unchanging).get(1) sess.close() # it is now detached I then need to tell other objects about about it, having a many-to-one relationship to 'unchanging': sess1 =

Re: [sqlalchemy] A long-lived ORM object

2012-02-08 Thread Michael Hipp
On 2012-02-08 9:50 AM, Michael Bayer wrote: unchanging = sess1.merge(unchanging, dont_load=True) Thanks, Michael this seems to do what I need. But I notice in the docs the kwarg appears to be 'load=False'. Am I looking at the wrong thing?

[sqlalchemy] Using a standalone SEQUENCE

2012-02-03 Thread Michael Hipp
/latest/core/schema.html#sqlalchemy.schema.Sequence Thanks, Michael Hipp -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr

Re: [sqlalchemy] empty a many-many table

2012-01-06 Thread Michael Hipp
On 2012-01-05 1:24 PM, Michael Bayer wrote: On Jan 5, 2012, at 9:57 AM, Michael Hipp wrote: Working from the many-many example in the tutorial [1], it has an association table like this: post_keywords = Table('post_keywords', Base.metadata, Column('post_id', Integer, ForeignKey('posts.id

[sqlalchemy] empty a many-many table

2012-01-05 Thread Michael Hipp
Working from the many-many example in the tutorial [1], it has an association table like this: post_keywords = Table('post_keywords', Base.metadata, Column('post_id', Integer, ForeignKey('posts.id')), Column('keyword_id', Integer, ForeignKey('keywords.id')) ) Normally to just empty

Re: [sqlalchemy] Re: 0.7 event migration

2011-12-28 Thread Michael Hipp
On 2011-12-28 10:58 AM, Michael Bayer wrote: detach(), also nice. This seems most descriptive of what is actually taking place. I poured over the docs for some time looking for the detach() method. Michael -- You received this message because you are subscribed to the Google Groups

[sqlalchemy] Necessary to call session.close()?

2011-12-17 Thread Michael Hipp
How important is it to call session.close() when done with a session? Will things be automatically cleaned-up if all references to a session go out of scope? Thanks, Michael -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group,

Re: [sqlalchemy] Dirty columns?

2011-12-08 Thread Michael Hipp
On 2011-12-08 4:11 PM, Michael Bayer wrote: On Dec 8, 2011, at 4:55 PM, Michael Hipp wrote: I'm getting a dirty indication on a particular ORM object from session.is_modified(rec, passive=True) and also that same rec shows up in session.dirty. But I can't figure out where/how it's been

[sqlalchemy] Enforce range on Column(Numeric)

2011-10-28 Thread Michael Hipp
Could someone point me to a doc page that explains how to enforce a range limit on a Numeric type. I have some monetary values that I want to force to always be = Decimal('0.00'). Thanks, Michael -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To

[sqlalchemy] Troubles with LEFT OUTER JOIN

2011-02-15 Thread Michael Hipp
Can someone help me understand why I can't seem to do a simple left outer join between these two tables: q = self.session.query(Car, Invoice.id_) q = q.outerjoin(Car, Invoice) sqlalchemy.exc.ArgumentError: Can't find any foreign key relationships between 'cars' and 'cars'.

[sqlalchemy] Is outerjoin() not generative?

2011-02-15 Thread Michael Hipp
This works: Seller = aliased(Dealer) Buyer = aliased(Dealer) q = self.session.query(Car, Seller.name, Buyer.name) q = q.outerjoin((Car.seller, Seller), (Car.buyer, Buyer)) This doesn't: Seller = aliased(Dealer) Buyer = aliased(Dealer) q =

[sqlalchemy] SELECT ARRAY(SELECT ...

2010-11-09 Thread Michael Hipp
Can someone show me the gist of how to construct an SA query that produces SQL* of the form SELECT ARRAY(SELECT ... FROM ... WHERE ...) as array_col Thanks, Michael * http://www.postgresql.org/docs/8.4/interactive/sql-expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS -- You received this

Re: [sqlalchemy] Re: SELECT ARRAY(SELECT ...

2010-11-09 Thread Michael Hipp
On 11/9/2010 3:55 PM, Gunnlaugur Briem wrote: select([ func.ARRAY( select([t.c.value]) .where(t.c.id3) .as_scalar() ) .label('array_col') ]) Thank you! That works swimmingly. I now know why my search didn't turn up anything as it is evidently one of those If the

Re: [sqlalchemy] Re: InternalError

2010-11-06 Thread Michael Hipp
On 11/6/2010 12:15 AM, Christopher Grebs wrote: this is just some specific PostgreSQL behaviour. If there's an error in a transaction it closes the transaction and nothing can be done with it anymore. You need to catch such errors and close the session or at least commit to close the

[sqlalchemy] InternalError

2010-11-05 Thread Michael Hipp
I'm doing a simple query like this, to get a list of dealers with open invoices: session.query(Invoice.dealer_id, Dealer.name). outerjoin((Dealer, Invoice.dealer)). group_by(Invoice.dealer_id, Dealer.name). all() Which produces this SQL: SELECT invoices.dealer_id AS

Re: [sqlalchemy] InternalError

2010-11-05 Thread Michael Hipp
On 11/5/2010 2:50 PM, Michael Hipp wrote: That SQL runs perfectly when given directly to PostgreSQL, but SQLAlchemy is reporting a DB-API error: sqlalchemy.exc.InternalError: (InternalError) current transaction is aborted, commands ignored until end of transaction block Nevermind. I noticed

[sqlalchemy] Subtransactions

2010-11-01 Thread Michael Hipp
If I do this: item1 = Item() # a new item self.sess.add(item1) self.sess.begin(subtransactions=True) # sub transaction item2 = Item() # another self.sess.add(item2) self.sess.rollback() # rollback sub trans cnt = self.sess.query(Item).count() # how many? That

Re: [sqlalchemy] Subtransactions

2010-11-01 Thread Michael Hipp
On 11/1/2010 10:19 AM, Michael Bayer wrote: SAVEPOINT. This is the technique the average user wants to use. Thanks for that. Pertinent documentation: begin(): When a rollback is issued, the subtransaction will directly roll back the innermost *real* transaction. rollback(): This method rolls

Re: [sqlalchemy] Subtransactions

2010-11-01 Thread Michael Hipp
On 11/1/2010 11:33 AM, Michael Bayer wrote: OK I think in this case, as in many others, is that subtransactions are not an easy to learn feature, hence it is controlled by a flag that is off by default. ... ... for features that aren't intended for typical use Then perhaps say that. This

Re: [sqlalchemy] Subtransactions

2010-11-01 Thread Michael Hipp
On 11/1/2010 3:12 PM, Michael Bayer wrote: new section: http://www.sqlalchemy.org/docs/orm/session.html#using-subtransactions This section now attempts to explain the full purpose and rationale of the subtransactions feature including an example. Hope it's clear. Thank you, looks

[sqlalchemy] DataError: invalid input value for enum

2010-10-31 Thread Michael Hipp
I have a model that looks something like this: TRANS_CODES = ( 'SellCar', 'BuyCar', 'BuyFee', 'SellFee', 'Gas/Fuel', 'Detail', 'Wash/Vac', 'Trans/Hauling', 'Service/Repair', 'DraftFee', 'Misc', 'Cash', 'CheckPaid', 'CheckRcvd', 'FloorPlan', 'Draft') class Trans(Base): __tablename__

Re: [sqlalchemy] orm object, before after

2010-10-16 Thread Michael Hipp
On 8/24/2010 9:47 PM, Michael Bayer wrote: Michael Hipp wrote: How do I make a copy of an orm object such that modifications to the copy do not affect the original? The mapped object has a member _sa_instance_state that you basically don't want to transfer to your new object.You want

Re: [sqlalchemy] orm object, before after

2010-10-16 Thread Michael Hipp
On 10/16/2010 12:52 PM, Michael Bayer wrote: On Oct 16, 2010, at 1:02 PM, Michael Hipp wrote: On 8/24/2010 9:47 PM, Michael Bayer wrote: Michael Hipp wrote: How do I make a copy of an orm object such that modifications to the copy do not affect the original? The mapped object has a member

Re: [sqlalchemy] orm object, before after

2010-10-16 Thread Michael Hipp
On 10/16/2010 1:55 PM, Michael Bayer wrote: On Oct 16, 2010, at 2:03 PM, Michael Hipp wrote: On 10/16/2010 12:52 PM, Michael Bayer wrote: On Oct 16, 2010, at 1:02 PM, Michael Hipp wrote: On 8/24/2010 9:47 PM, Michael Bayer wrote: Michael Hipp wrote: How do I make a copy of an orm object

[sqlalchemy] When is 'default' applied?

2010-10-15 Thread Michael Hipp
If I have a column defined like this: qty = Column(Numeric, nullable=False, default=Decimal('1')) When is the default applied? At commit()? Michael -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to

Re: [sqlalchemy] When is 'default' applied?

2010-10-15 Thread Michael Hipp
On 10/15/2010 5:30 PM, Michael Hipp wrote: If I have a column defined like this: qty = Column(Numeric, nullable=False, default=Decimal('1')) When is the default applied? At commit()? Nevermind. Finally found it in the docs, appears it happens at INSERT time. Thanks, Michael -- You received

Re: [sqlalchemy] Empty a record

2010-09-22 Thread Michael Hipp
On 9/22/2010 10:27 AM, Michael Bayer wrote: Michael, thanks so much for taking the time to compose a very thorough answer. If you could indulge a few clarifications/suggestions ... So here, the value of None for car.auction, merges into the session which becomes a pending change. The

Re: [sqlalchemy] Change echo at will

2010-09-22 Thread Michael Hipp
On 8/26/2010 8:55 PM, Mike Conley wrote: On Thu, Aug 26, 2010 at 4:21 PM, Michael Hipp mich...@hipp.com mailto:mich...@hipp.com wrote: Is there a way to set 'echo' at any time? Everything I can find sets it when the engine is created and doesn't seem to change it afterward. You can

Re: [sqlalchemy] Empty a record

2010-09-22 Thread Michael Hipp
On 9/22/2010 11:21 AM, Michael Hipp wrote: new = Car() new.id_ = old.id_ new = sess.merge(new) new.auction = old.auction # do this *after* merge sess.commit() This seems to work and ... Bah. I spoke too soon - it just doesn't throw an exception. But without explicitly setting

Re: [sqlalchemy] Empty a record

2010-09-22 Thread Michael Hipp
On 9/22/2010 5:24 PM, Michael Bayer wrote: Here's the problem. The term a blank record is meaningless. Well, no, it's not. It's exactly what I get when I do new=Item() and commit(). It's very well defined, precise, and repeatable. Trying to make other tools guess this for you seems to be

Re: [sqlalchemy] Use regexp in like

2010-09-21 Thread Michael Hipp
On 9/20/2010 10:54 AM, Michael Hipp wrote: On 9/20/2010 10:09 AM, Michael Hipp wrote: On 9/20/2010 9:38 AM, Michael Hipp wrote: Scratch that ... found this message: http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg18598.html which says I should be able to do a 'SIMILAR TO' construct

[sqlalchemy] Empty a record

2010-09-21 Thread Michael Hipp
I need to empty an item (row). I thought to do this: new = Item() # create a new empty object new.id_ = old.id_ # copy certain other fields also self.session.expunge(old) self.session.add(new) self.session.commit() But it seems SA still tries to save it with an INSERT. (I

Re: [sqlalchemy] Use regexp in like

2010-09-21 Thread Michael Hipp
On 9/21/2010 7:23 AM, Michael Bayer wrote: On Sep 21, 2010, at 8:12 AM, Michael Hipp wrote: On 9/20/2010 10:54 AM, Michael Hipp wrote: On 9/20/2010 10:09 AM, Michael Hipp wrote: On 9/20/2010 9:38 AM, Michael Hipp wrote: Scratch that ... found this message: http://www.mail-archive.com

Re: [sqlalchemy] Empty a record

2010-09-21 Thread Michael Hipp
On 9/21/2010 7:31 AM, Michael Hipp wrote: I need to empty an item (row). I thought to do this: new = Item() # create a new empty object new.id_ = old.id_ # copy certain other fields also self.session.expunge(old) self.session.add(new) self.session.commit() But it seems SA still tries to save

Re: [sqlalchemy] Empty a record

2010-09-21 Thread Michael Hipp
On 9/21/2010 8:17 PM, Michael Bayer wrote: It definitely does not attempt an INSERT if id_ is set to a non-None value, assuming that row already exists in the DB, without something else in your model/usage causing that to happen.If id_ is None or the given id_ doesn't exist in the DB, you

Re: [sqlalchemy] Use regexp in like

2010-09-20 Thread Michael Hipp
On 9/20/2010 9:38 AM, Michael Hipp wrote: Scratch that ... found this message: http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg18598.html which says I should be able to do a 'SIMILAR TO' construct which is perhaps somewhat more lightweight than a full regexp. Can someone show me

Re: [sqlalchemy] Use regexp in like

2010-09-20 Thread Michael Hipp
On 9/20/2010 10:09 AM, Michael Hipp wrote: On 9/20/2010 9:38 AM, Michael Hipp wrote: Scratch that ... found this message: http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg18598.html which says I should be able to do a 'SIMILAR TO' construct which is perhaps somewhat more lightweight

Re: [sqlalchemy] Use regexp in like

2010-09-20 Thread Michael Hipp
On 9/20/2010 10:57 AM, Michael Bayer wrote: On Sep 20, 2010, at 11:54 AM, Michael Hipp wrote: On 9/20/2010 10:09 AM, Michael Hipp wrote: On 9/20/2010 9:38 AM, Michael Hipp wrote: Scratch that ... found this message: http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg18598.html which

Re: [sqlalchemy] Use regexp in like

2010-09-17 Thread Michael Hipp
On 9/14/2010 2:23 PM, Michael Hipp wrote: Is it possible to use a regexp in a like() clause? Or some other way to achieve something similar? Can anyone suggest an approach to search a field with a regexp? Thanks, Michael -- You received this message because you are subscribed to the Google

[sqlalchemy] Use regexp in like

2010-09-14 Thread Michael Hipp
Is it possible to use a regexp in a like() clause? Or some other way to achieve something similar? Thanks, Michael -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe

[sqlalchemy] Change echo at will

2010-08-26 Thread Michael Hipp
Is there a way to set 'echo' at any time? Everything I can find sets it when the engine is created and doesn't seem to change it afterward. Thanks, Michael -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to

Re: [sqlalchemy] orm object, before after

2010-08-25 Thread Michael Hipp
On 8/24/2010 9:47 PM, Michael Bayer wrote: Michael Hipp wrote: How do I make a copy of an orm object such that modifications to the copy do not affect the original? x = MyObject() for a in dir(myoldobject): if not a.startswith('_'): setattr(x, a, getattr

[sqlalchemy] orm object, before after

2010-08-24 Thread Michael Hipp
I'm holding an orm object that will have changes made to it. Once done it will be passed to the business logic layer that will have to make decisions from the before and after state of the object... What's the best way to get an object, save its state ('before'), modify it ('after) without

Re: [sqlalchemy] orm object, before after

2010-08-24 Thread Michael Hipp
On 8/24/2010 1:51 PM, Michael Bayer wrote: On Aug 24, 2010, at 2:08 PM, Michael Hipp wrote: I'm holding an orm object that will have changes made to it. Once done it will be passed to the business logic layer that will have to make decisions from the before and after state of the object

[sqlalchemy] Adjacency List Relationships using declarative

2010-08-21 Thread Michael Hipp
I'm trying to do exactly what is described here: http://www.sqlalchemy.org/docs/mappers.html#adjacency-list-relationships But I'm using declarative. Here's what I have but it fails with the exception below: class Option(Base): __tablename__ = 'options' id_ = Column(Integer,

Re: [sqlalchemy] Adjacency List Relationships using declarative

2010-08-21 Thread Michael Hipp
On 8/21/2010 6:00 PM, Michael Bayer wrote: On Aug 21, 2010, at 5:16 PM, Michael Hipp wrote: How do I make this work with declarative? If you were to use string literals with remote_side here, its the full expression would be a string, i.e. remote_side=Option.id_. But that's not needed here

Re: [sqlalchemy] Which columns changing during orm commit?

2010-08-19 Thread Michael Hipp
On 8/19/2010 5:24 AM, Chris Withers wrote: Michael Hipp wrote: SQLAlchemy seems pretty smart about updating only the changed columns in an orm object... If I have an orm object. Something changes one of the columns. Just before I commit() the session, is there a way to tell which columns

[sqlalchemy] Which columns changing during orm commit?

2010-08-18 Thread Michael Hipp
SQLAlchemy seems pretty smart about updating only the changed columns in an orm object... If I have an orm object. Something changes one of the columns. Just before I commit() the session, is there a way to tell which columns will be updated vs those that are unchanged? Any way to ascertain

[sqlalchemy] Performance: orm vs sql

2010-08-18 Thread Michael Hipp
The little diddly below is comparing performance of orm access vs sql expression language. When I run it with number=1 I get a 5.8x advantage for sql. When I run it 10 times I get a 2.7x advantage. The actual numbers are, respectively: 1.47375132 0.25630808 5.45569524 1.96911144 Is this a

[sqlalchemy] Alias for a joined column name

2010-08-16 Thread Michael Hipp
I'm doing something like this where each Item has 2 ForeignKeys to Dealer for buyer and seller: seller = dealers.alias('seller') buyer = dealers.alias('buyer') engine.execute(select([items, seller.c.name, buyer.c.name]).fetchall() When I do this the seller and buyer name end up in the

Re: [sqlalchemy] Alias for a joined column name

2010-08-16 Thread Michael Hipp
On 8/16/2010 5:12 PM, Conor wrote: On 08/16/2010 04:47 PM, Michael Hipp wrote: I'm doing something like this where each Item has 2 ForeignKeys to Dealer for buyer and seller: seller = dealers.alias('seller') buyer = dealers.alias('buyer') engine.execute(select([items, seller.c.name

[sqlalchemy] DetachedInstanceError

2010-08-14 Thread Michael Hipp
I'm obviously missing some key concept as regards the management of sessions. This seemingly simple usage fails: def get_new(): sess = Session() new = Something() # new orm object sess.add(new) sess.commit() sess.close() return new new = get_new() # request a new

Re: [sqlalchemy] DetachedInstanceError

2010-08-14 Thread Michael Hipp
, at 12:53 PM, Michael Hipp wrote: I'm obviously missing some key concept as regards the management of sessions. This seemingly simple usage fails: def get_new(): sess = Session() new = Something() # new orm object sess.add(new) sess.commit() sess.close() return new new = get_new() # request a new

Re: [sqlalchemy] DetachedInstanceError

2010-08-14 Thread Michael Hipp
On 8/14/2010 2:29 PM, Michael Bayer wrote: The approach above may be fine for your needs but I wouldn't encourage it. The demarcation of transaction boundaries shouldn't be an ad-hoc thing IMO and granular functions shouldn't be deciding whether or not they are setting up a transaction.

Re: [sqlalchemy] Error creating backref

2010-08-07 Thread Michael Hipp
On 8/6/2010 9:04 PM, Michael Hipp wrote: Can someone help me figure out why I keep getting the error below. Here are my 3 models. It's a simple many-one on banks-dealer and reps-dealer. class Dealer(Base): __tablename__ = 'dealers' id_ = Column(Integer, primary_key=True) reps = relationship

[sqlalchemy] Error creating backref

2010-08-06 Thread Michael Hipp
Can someone help me figure out why I keep getting the error below. Here are my 3 models. It's a simple many-one on banks-dealer and reps-dealer. class Dealer(Base): __tablename__ = 'dealers' id_ = Column(Integer, primary_key=True) reps = relationship('Rep', order_by='Rep.lname',

Re: [sqlalchemy] create_all() fails silently

2010-08-05 Thread Michael Hipp
On 8/4/2010 10:03 PM, Mike Conley wrote: On Wed, Aug 4, 2010 at 9:39 PM, Michael Hipp mich...@hipp.com mailto:mich...@hipp.com wrote: Can someone tell me why this code won't create any tables? The tables are defined in another file that calls declarative_base(). I presume

Re: [sqlalchemy] create_all() fails silently

2010-08-05 Thread Michael Hipp
On 8/5/2010 8:26 AM, Mike Conley wrote: On Thu, Aug 5, 2010 at 6:29 AM, Michael Hipp mich...@hipp.com mailto:mich...@hipp.com wrote: On 8/4/2010 10:03 PM, Mike Conley wrote: Thanks. But by the time I'm done there will be at least a dozen of those otherfiles. Which one do I get

[sqlalchemy] Can an object span sessions?

2010-08-05 Thread Michael Hipp
Can this be made to work? session = Session() rec = MyModel() # create a record session.close() # Sometime later session = Session() rec.name = Fred # modify the record session.commit() # try to save modified record session.close() Does the session have to be global to this

Re: [sqlalchemy] Can an object span sessions?

2010-08-05 Thread Michael Hipp
On 8/5/2010 11:03 AM, Michael Bayer wrote: On Aug 5, 2010, at 11:54 AM, Michael Hipp wrote: Can this be made to work? session = Session() rec = MyModel() # create a record session.close() # Sometime later session = Session() rec.name = Fred # modify the record session.commit

[sqlalchemy] Basic query questions ...

2010-08-04 Thread Michael Hipp
Hello, a couple of really basic questions ... 1) How do I write a query beforehand that will be evaluated later at some other place in the code? (Note that the session hopefully won't exist until that later time.) Also, certain parameters may need to be passed to the query at eval time (e.g.

[sqlalchemy] create_all() fails silently

2010-08-04 Thread Michael Hipp
Can someone tell me why this code won't create any tables? The tables are defined in another file that calls declarative_base(). I presume the problem is that it doesn't know which tables to create. If so, how do I tell it what tables to create? Base = declarative_base() database =

[sqlalchemy] Close the engine and go home

2010-07-17 Thread Michael Hipp
This is a really dumb noob question... I know how to create an engine, a Session, and a session. I see how to do session.close(). How do I close the engine? (i.e. How do I close all connections to the database cleanly so my application can exit and not leave the database server hanging?)

[sqlalchemy] Opportunistic locking or edit sequence

2008-05-16 Thread Michael Hipp
this by using a field like 'edit_sequence' which is an incrementing sequence where the value in the db must match that in the UPDATE. Does SA have such a feature or something like it? Thanks, Michael Hipp Heber Springs, Arkansas, USA --~--~-~--~~~---~--~~ You