[sqlalchemy] Re: How to replace a property in a declarative way

2009-09-28 Thread Kees van den Broek
Here is how I would construct the colors relation (put this inside the Product declaration): Hi Conor, Thank you for your documented implementation. Works as advertised! Cheers, Kees --~--~-~--~~~---~--~~ You received this message because you are subscribed

[sqlalchemy] How to replace a property in a declarative way

2009-09-22 Thread Kees van den Broek
Hi, I simplified my problem to a small example (see model below). A Product has several Tags attached. A beachball is green, blue, round and big: p=Product() p.name = Beachball p.tags = [greenTag, blueTag, roundTag, bigTag] DBSession.save(p) Often I just want to see the color-related tags, not

[sqlalchemy] Implement the associationproxy example using __mapper_args__

2009-08-30 Thread Kees van den Broek
Hi, I'm using the association_proxy example: http://www.sqlalchemy.org/docs/05/reference/ext/associationproxy.html?highlight=associationproxy#building-complex-views The example uses this mapper definition: mapper(Broker, brokers_table, properties={ 'by_stock': relation(Holding,

[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 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] Specify join_depth with eagerload()

2009-08-04 Thread Kees van den Broek
Hi, All the information I need, I can get in 1 SQL query with this query and model: categories=Article.query.filter(Article.parent == None).all() class Article(DefaultEntity): name = Field(Unicode(64), index=True) parent = ManyToOne('Article') children = OneToMany('Article',

[sqlalchemy] Re: Creating ClauseElements programmatically in a loop

2009-08-01 Thread Kees van den Broek
On Jul 31, 7:55 pm, Michael Bayer mike...@zzzcomputing.com wrote: or_() returns the first argument if theres only one argument.   youre looking for or_(*map(...)) Thanks, that's exactly what I was looking for. --~--~-~--~~~---~--~~ You received this message

[sqlalchemy] Creating ClauseElements programmatically in a loop

2009-07-31 Thread Kees van den Broek
Hi, I'd like to create a query at run time with any amount of filters wrapped in an 'OR'. What's the right syntax to do this? This was my best attempt so far: from sqlalchemy import * id=[1,2] q=Province.query.filter(or_(map(lambda n: Province.id == n, id)))