Re: [sqlalchemy] [Q][0.7.9] How to issue apply_labels() on an ORM query?
On Friday, May 31, 2013 11:46:46 AM UTC+2, Ladislav Lenart wrote: Glad I could help, but I don't understand what is going on. Neither ticket description nor the patch itself helped me. Sorry. What is select_from() good for when it generates a cartesian query? What MIGHT help ME (a lot infact) is a couple of DOs and DONTs examples in one place for all these three constructs OR A 'highlevel user-friendly step-by-step description' about what each construct does, so that I can see where they differ. Hi, Lenart! In the patch you can find doc for the new method Query.select_entity_from. As I read it, it replaces Query.select_from. Have you tried simply replacing old method with the new one (after applying the patch)? a. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] [Q][0.7.9] How to issue apply_labels() on an ORM query?
On Fri, May 31, 2013 at 12:31 PM, Ladislav Lenart lenart...@volny.czwrote: Hello. I've read the patch and the new documentation and i've learned about the existence of select_entity_from(). I was trying to say that the new documentation does not help me to understand the meaning / preferred usage of these constructs (i.e. select_from, select_entity_from and aliased). I simply don't understand when should I use which and why. I have already solved my original problem by replacing select_from() with add_entity() and join(). Take a look at older posts in this thread for more details if you're interested, though the original query is a bit more involved than the supplied regression. Ladislav Lenart Sorry I rushed with the reply! I haven't carefully read your original post, but concentrated on the patch as I was hoping it was relevant to my issue. More importantly, I was misleading and wrong in trying to 'summarize' the docs, stating there are new and old methods. The examples in the patch say those two cases: select_stmt = select([User]).where(User.id == 7) q = session.query(User).select_entity_from(select_stmt) user_from_select = aliased(User, select_stmt.alias()) should produce similar result, i.e. give you User entity from different mapping then usual; whether select_from() should work as intended - resulting cartesian product in docs example should be 'eliminated' by further join. Cheers, a. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] object has no attribute 'delete'
http://www.sqlalchemy.org/docs/ormtutorial.html#deleting On 13 April 2010 11:12, jo jose.soa...@sferacarta.com wrote: Hi all, I'm trying migrate from 0.3 to 0.6 I don't know how to delete an object in the old version it was: My.get(1).delete() in 0.6: My.get(1).delete() AttributeError: 'My' object has no attribute 'delete' -- 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 from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Cannot delete SQLite '.db' using os.remove
Your example runs fine on Ubuntu 9.04, with python 2.6.2 and SQLAlchemy-0.6beta1. On 9 March 2010 05:49, Lynton Grice lyntongr...@gmail.com wrote: Hi Michael, Can you paste the following code into your editor and try it out? Can you tell me what I would need to do to close the connections in this case? Any help would be greatly appreciated ;-) from sqlalchemy import * from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import mapper from sqlalchemy.pool import StaticPool import os class Message(object): pass if __name__ == '__main__': db_conn = 'sqlite:///foo.db' db = create_engine(db_conn,echo=False, poolclass=StaticPool) metadata = MetaData(db) queueName = 'foo' queue = Table(queueName, metadata, Column('IDX', Integer, primary_key=True, autoincrement = True ), Column('ID', String(64)), Column('CORRELATIONID', String(64)),) queue.create() session_maker = sessionmaker(bind=db) session = session_maker() mapper(Message, queue) msg = Message() msg.ID = '1234' msg.CORRELATIONID = '111' session.add(msg) session.commit() print Message count: + str(session.query(Message).count()) db.dispose() os.remove('foo.db') print Done... Thanks Lynton -- 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 from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: How to order_by relation by another join?
Thanks, Mike! Your example indeed works, but unfortunately when I add inheritance, mapper fails to generate proper (inherited) class: (I've changed code a little, so it represents more what I'm trying to do) from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base engine = create_engine('sqlite://', echo=True) Base = declarative_base() class Detail(Base): __tablename__ = 'detail' id = Column(Integer, primary_key=True) sort = Column(Integer) class Order(Base): __tablename__ = 'order' id = Column(Integer, primary_key=True) class Item(Base): __tablename__ = 'item' id = Column(Integer, primary_key=True) order_id = Column(Integer, ForeignKey('order.id')) detail_id = Column(Integer, ForeignKey('detail.id')) detail = relation(Detail, uselist=False, lazy=False) order = relation(Order, uselist=False) type = Column(String(20)) __mapper_args__ = { 'polymorphic_on' : type} class ValueItem(Item): __mapper_args__ = { 'polymorphic_identity' : 'quantity' } value = Column('quantity_value', Numeric(15, 4)) class ErrorItem(Item): __mapper_args__ = { 'polymorphic_identity' : 'error' } value = Column('error_value', String(15, 4)) Order.items = relation(Item) j = Item.__table__.join(Detail.__table__) itemdetail = mapper(Item, j, non_primary=True) Order.sorteditems = relation(itemdetail, order_by=Detail.__table__.c.sort, viewonly=True) metadata = Base.metadata metadata.create_all(engine) Session = scoped_session(sessionmaker(bind=engine)) order = Order(id=1) Session.add(order) detail = Detail(id=1, sort=1) order.items.append(ValueItem(id=1, detail=detail)) Session.commit() for order in Session.query(Order).all(): for item in order.sorteditems: print item for item in order.items: print item ... __main__.Item object at 0x881ddac __main__.ValueItem object at 0x960da6c Am I making a obvious mistake somewhere here? -- 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 from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: How to order_by relation by another join?
On 11 February 2010 14:26, Michael Bayer mike...@zzzcomputing.com wrote: I'm assuming these are single-table inheritance mappers (I forgot about that add the column trick..) So yeah my solution was a quick hack and to continue in this way you'd have to build non-primary mappers for each of ValueItem, ErrorItem that state inherits for the original non-primary mapper, using the polymorphic identities as well. It would still work. Thanks again! It's obvious now, of course. When I added other non-primary mappers, inheritance is working. I suppose declarative extension spoiled me... -- 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 from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] How to order_by relation by another join?
Let's say I've got simple structure Order--Item--Detail. class Detail(Base): ... class Order(Base): ... class Item(Base): ... detail = relation(Detail, uselist=False, lazy=False) order = relation(Order, uselist=False, backref='items') Of course I can specify order_by for Order.items by any columns from Item, but is there a way I can order_by a column defined in Detail? I've naively tried something as backref('items', order_by=Detail.id), but because Detail is anonymously joined to Item as e.g. 'details_1', I've received ProgrammingError: invalid reference to FROM-clause entry for table details. -- 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 from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.