[sqlalchemy] Re: negative indexes in query slices?

2009-08-24 Thread King Simon-NFHD78
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of john smallberries Sent: 24 August 2009 08:51 To: sqlalchemy Subject: [sqlalchemy] negative indexes in query slices? I just tried limiting a query to the final 10 items of a

[sqlalchemy] ForeignKey on a ForeignKey

2009-08-24 Thread Laurent Rahuel
Hi all, I'm stucked with a problem I'm not able to solve (SA 0.5.2). I hope on of you would be smarter than me. Here is the problem: import sqlalchemy as sa __metadata__ = sa.MetaData() OBJECTS = sa.Table('objects', __metadata__, sa.Column('id', sa.Integer, primary_key=True),

[sqlalchemy] Re: ForeignKey on a ForeignKey

2009-08-24 Thread King Simon-NFHD78
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of Laurent Rahuel Sent: 24 August 2009 12:16 To: sqlalchemy Subject: [sqlalchemy] ForeignKey on a ForeignKey Hi all, I'm stucked with a problem I'm not able to solve (SA

[sqlalchemy] Re: ForeignKey on a ForeignKey

2009-08-24 Thread asrenzo
Hi King Simon, Thanks for your answer but this doesn't solve my problem. If I comment my parent_id definition in the objects_tree definition, everything is OK with create_all() invocation. If I change the parent_id column definition to : sa.Column('parent_id', None, sa.ForeignKey('objects.id',

[sqlalchemy] Re: Possible to define composite mapping separate from underlying class implementation?

2009-08-24 Thread Michael Bayer
hal_robertson wrote: AttributeError: 'Z' object has no attribute '__composite_values__' using sqlalchemy.orm.composite to map instances of Z to composite tables requires that Z define __init__, __composite_values__, and ideally __set_composite_values__, and __eq__, which are specific to how

[sqlalchemy] Re: negative indexes in query slices?

2009-08-24 Thread john smallberries
An error would be swell. I'd already moved on to the saner solution you mentioned, but was curous about the dont-say-limit-just-say-slice advice I had seen, since I'd reflexively written it that way against an ordered index query. On Aug 24, 7:21 am, Michael Bayer mike...@zzzcomputing.com wrote:

[sqlalchemy] Re: Possible to define composite mapping separate from underlying class implementation?

2009-08-24 Thread hal_robertson
Hmm... I must be missing something then in the mapping This is the error I'm getting: AttributeError: 'Z' object has no attribute '__composite_values__' How do I do the mapping so that the Z instances map to the respective composite tables correctly? I assume then I do not want to use

[sqlalchemy] making an instance read-only

2009-08-24 Thread Martijn Faassen
Hi there, I'm investigating ways to make an ORM-mapped instance read-only, dependent the value of a particular attribute (database backed or not). If an object has a certain state, I want to prevent normal users from making a modification. Other objects connected to the same session should

[sqlalchemy] cloning ORM-mapped instances

2009-08-24 Thread Martijn Faassen
Hi there, I'm looking into a reliable way to clone ORM-mapped instances, so that the clone, with some modifications, can be re-added to the database. I saw the following thread: http://groups.google.com/group/sqlalchemy/browse_thread/thread/6e162f9a74697a01/6396c677b2a87797#6396c677b2a87797

[sqlalchemy] Re: Possible to define composite mapping separate from underlying class implementation?

2009-08-24 Thread Michael Bayer
hal_robertson wrote: Hmm... I must be missing something then in the mapping This is the error I'm getting: AttributeError: 'Z' object has no attribute '__composite_values__' How do I do the mapping so that the Z instances map to the respective composite tables correctly? I assume then

[sqlalchemy] Re: making an instance read-only

2009-08-24 Thread Michael Bayer
Martijn Faassen wrote: Hi there, I'm investigating ways to make an ORM-mapped instance read-only, dependent the value of a particular attribute (database backed or not). If an object has a certain state, I want to prevent normal users from making a modification. Other objects connected to

[sqlalchemy] association_proxy only returning one object instead of a list or group of objects

2009-08-24 Thread SmokeyD
Hey everyone, I am running into a problem with association_proxy attributes in SQLAlchemy 0.5 and python 2.6. I pasted my model (a simplified version) all the way below. My model has a Permission object, Project object and a Group object, and it uses an AccessRule object to grant a permission to

[sqlalchemy] composite primary key problem

2009-08-24 Thread Martijn Faassen
Hi there, I'm experimenting with a composite primary key to see whether it might help implement a workflow system, where the primary key consists of an identifier (code) and a workflow status. I run into an error with the ORM (in 0.5.5 and trunk) when I modify part of the primary key (the

[sqlalchemy] Unable to define a self-referential table in declarative style

2009-08-24 Thread Kees van den Broek
Hi, This is a table setup in declarative style: class Category(DeclarativeBase): __tablename__ = 'category' category_id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(255), unique=True, nullable=False) children = relation('Category',

[sqlalchemy] Re: Unable to define a self-referential table in declarative style

2009-08-24 Thread Tomasz Jezierski - Tefnet
Dnia 2009-08-24, Pn o godzinie 12:35 -0700, Kees van den Broek pisze: Hi, This is a table setup in declarative style: class Category(DeclarativeBase): __tablename__ = 'category' category_id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(255),

[sqlalchemy] Re: Unable to define a self-referential table in declarative style

2009-08-24 Thread Michael Bayer
you're missing a ForeignKey column back to your category_id. Kees van den Broek wrote: Hi, This is a table setup in declarative style: class Category(DeclarativeBase): __tablename__ = 'category' category_id = Column(Integer, autoincrement=True, primary_key=True) name =

[sqlalchemy] Re: composite primary key problem

2009-08-24 Thread Michael Bayer
the program works for me, I get: 2009-08-24 16:12:56,797 INFO sqlalchemy.engine.base.Engine.0x...1830 PRAGMA table_info(user) 2009-08-24 16:12:56,806 INFO sqlalchemy.engine.base.Engine.0x...1830 () 2009-08-24 16:12:56,807 INFO sqlalchemy.engine.base.Engine.0x...1830 CREATE TABLE user (

[sqlalchemy] wrong number of rows returned

2009-08-24 Thread DavidG
Hi, I can give all the details, but let's start with a simple question. I have a query, and it is returning the wrong number of rows! Not only is the number wrong compared to what I would expect, but, more importantly, when I paste the *exact sql* (except for substituting a param) printed on

[sqlalchemy] Re: Unable to define a self-referential table in declarative style

2009-08-24 Thread Kees van den Broek
That's it. Thanks! Although it still took me a while to figure out how to do it. Just to have a complete example in the mailinglist, I'll copy paste what I have now: class Category(DeclarativeBase): __tablename__ = 'category' category_id = Column(Integer, autoincrement=True,

[sqlalchemy] Re: wrong number of rows returned

2009-08-24 Thread Michael Bayer
Query(), when called with entity classes as arguments, returns only unique entities or unique combinations thereof. to get the raw data call Query with columns/attributes as arguments instead. DavidG wrote: Hi, I can give all the details, but let's start with a simple question. I have

[sqlalchemy] Re: Using a different set of engines for reading versus writing

2009-08-24 Thread phrrn...@googlemail.com
I like the sneaky way. I put the basic mechanism in place but I am not sure yet how to implement a useful and practical set of defaults (I am referring to stuff which is totally particular to our organization and not anything to do with SA). very cool. pjjH On Aug 12, 9:30 pm, Michael Bayer

[sqlalchemy] Re: wrong number of rows returned

2009-08-24 Thread DavidG
Hi Mike - Confused. Why would it be different with the limit() or not? Without the limit() I get *all* the Quote records (1000) which is correct. If I have something like limit(10), I'll get *less then 10*. Also, I didn't know about the unique entities limitation. In any event, the Quote

[sqlalchemy] Re: making an instance read-only

2009-08-24 Thread phrrn...@googlemail.com
I implemented a very crude flush/commit-time version of this today that disables all modifications. Michael suggested the use of connection_callable to provide fine-grained control of which engine to use for modifications. I haven't gone through all the details yet but it seems to work for my

[sqlalchemy] Re: cloning ORM-mapped instances

2009-08-24 Thread Jarrod Chesney
I used a mapper extension. On before_update, It will copy the record and add it to an array. On after_update, It will store the new record which is an exact copy of the old record before the update. Please note, I implemented a base class for my storage units this is the sqlaorm thing. It will

[sqlalchemy] Re: wrong number of rows returned

2009-08-24 Thread Michael Bayer
DavidG wrote: Hi Mike - Confused. Why would it be different with the limit() or not? well there's not enough detail to say exactly but you're applying the limit() to a query with outer join. So if Quote number one had five related Feedback entries, you'd get one row back for all five of

[sqlalchemy] Re: wrong number of rows returned

2009-08-24 Thread DavidG
First, there is at most a single Feedback record (for a given user, hence the subquery) per quote (and in the one case I have been banging my head on, I am certain of this). And this: why would I get different results from pasting the echoed sql into the online mysql query vs from sqlalchemy

[sqlalchemy] Re: wrong number of rows returned

2009-08-24 Thread Michael Bayer
On Aug 24, 2009, at 7:44 PM, DavidG wrote: First, there is at most a single Feedback record (for a given user, hence the subquery) per quote (and in the one case I have been banging my head on, I am certain of this). And this: why would I get different results from pasting the echoed