[sqlalchemy] Re: Defining a relationship without a foreign key constraint?

2011-03-16 Thread Eric Ongerth
Mike's suggestion is correct, and I want to add that relationship() / relation() do not require a foreign key constraint, they just are able to figure out the mapping more automatically (without a primaryjoin argument in unambiguous cases) if you do have one existing on the table. On Mar 15,

[sqlalchemy] subquery as a mapper property

2011-03-16 Thread hoesley
I am trying to create a property on a mapped class which basically executes a subquery. Here is what I'm trying to do in non-working pseudo code: mapper(OrderChain, Table('order_chains',self.meta, autoload=True), properties={'entries': relation(OrderChainEntry,

[sqlalchemy] attribute not updating

2011-03-16 Thread writeson
Hi all, This is probably a simple problem, but so far I haven't figured out how to resolve it. I've got some SqlAlchemy tables and am trying to change an attribute of a SqlAlchemy object returned from a query. However, when I change the attribute value, no SQL update statement is generated by the

Re: [sqlalchemy] subquery as a mapper property

2011-03-16 Thread Michael Bayer
this kind of pattern is usually handled by column_property(), assuming you can correlate your subquery to the parent within the WHERE clause such that the return value is a scalar. Below if you really just wanted the first row you'd want to say limit(1). If you really want that exact same

Re: [sqlalchemy] attribute not updating

2011-03-16 Thread Michael Bayer
On Mar 16, 2011, at 3:38 PM, writeson wrote: Hi all, This is probably a simple problem, but so far I haven't figured out how to resolve it. I've got some SqlAlchemy tables and am trying to change an attribute of a SqlAlchemy object returned from a query. However, when I change the

[sqlalchemy] Re: attribute not updating

2011-03-16 Thread writeson
Michael, there's nothing obviously wrong with the above other than the unusual naming scheme of Col, Int, and FK.     Two steps to take are to assert that the object is dirty, assert item in session.dirty, and the attribute has a change,  from sqlalchemy.orm import attributes; assert

[sqlalchemy] Re: two-way attribute relationships through associationproxy

2011-03-16 Thread Eric Ongerth
I hope this makes sense, what I'm trying to do here. My naive first try at it was to just see if I could have the desired backref()s on either the A or C class, and manage to have the relationship go through the associationproxy. Probably I should be thinking of a technical reason why we would

Re: [sqlalchemy] Re: attribute not updating

2011-03-16 Thread Michael Bayer
On Mar 16, 2011, at 4:09 PM, writeson wrote: Michael, there's nothing obviously wrong with the above other than the unusual naming scheme of Col, Int, and FK. Two steps to take are to assert that the object is dirty, assert item in session.dirty, and the attribute has a change,

[sqlalchemy] trouble with metaclass

2011-03-16 Thread farcat
I have an error i cant figure out (likely a beginners error): # Base = declarative_base() class tablemeta(DeclarativeMeta): def __new__(mcls, name): return DeclarativeMeta.__new__(mcls, name, (Base,), {}) def _init__(cls,

[sqlalchemy] Getting instances that contains other instances in an N:M relationship

2011-03-16 Thread Hector Blanco
Hello everyone! In my application I have a class Store that can contain several UserGroups (for permission purposes) and one UserGroup can belong to several Stores. I want to get the Stores that contain a certain UserGroup (instance): I have it modeled like this: class Store(declarativeBase):

[sqlalchemy] Re: Getting instances that contains other instances in an N:M relationship

2011-03-16 Thread Hector Blanco
Cr*p!... 5 minutes after writing, I got it: query = session.query(Store.Store).select_from(join(Store.Store, UserGroup.UserGroup, Store.Store.userGroups)).filter(UserGroup.UserGroup.id == int(userGroupId)) http://www.sqlalchemy.org/docs/orm/tutorial.html#querying-with-joins Well... it may help

[sqlalchemy] Re: Getting instances that contains other instances in an N:M relationship

2011-03-16 Thread Hector Blanco
Hello everyone! I am reopening that because now I want to go an step further... And I'm having troubles. Let's say I have an Store class that has a relationship pointing to UserGroup that has a relationship pointing to Users. I'm trying to create a method getStoresByUserId(parameterUserId)

[sqlalchemy] Association proxy like for integer/string/types list

2011-03-16 Thread zaza witch
Hi everyone, I am currently in work experience ... The first step of my work was to build a small application using sqlalchemy. Association proxy seems to allow to simplify many-to-many relationships management. Can i use it to store define a class with an attribute which is a list of string

Re: [sqlalchemy] Association proxy like for integer/string/types list

2011-03-16 Thread Michael Bayer
On Mar 16, 2011, at 8:12 PM, zaza witch wrote: Hi everyone, I am currently in work experience ... The first step of my work was to build a small application using sqlalchemy. Association proxy seems to allow to simplify many-to-many relationships management. Can i use it to store