Re: [sqlalchemy] Declarative classproperty member problem in 0.6.4, not 0.6.3

2010-09-15 Thread Michael Bayer
On Sep 15, 2010, at 12:10 PM, Chris Withers wrote: On 15/09/2010 15:04, Nikolaj wrote: Base = declarative_base() class Person(Base): __tablename__ = 'people' name = Column(String, primary_key=True) @classproperty def bar(cls): return cls.foo Can you

Re: [sqlalchemy] declarative base - can a relationship be used within a column_property?

2010-08-21 Thread Michael Bayer
On Aug 21, 2010, at 1:38 PM, Michael Bayer wrote: On Aug 19, 2010, at 6:38 AM, Yap Sok Ann wrote: With declarative base, is it possible to use a relationship within a column_property? you mean, as I am seeing below, to use the any() operator produced by a relationship... Here's

[sqlalchemy] declarative base - can a relationship be used within a column_property?

2010-08-19 Thread Yap Sok Ann
With declarative base, is it possible to use a relationship within a column_property? Here's some sample code to illustrate what I want to achieve: from sqlalchemy.engine import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import column_property,

Re: [sqlalchemy] Declarative syntax with column_property (v0.6.3)

2010-08-03 Thread Robert Sudwarts
Hi Michael, I'm guilty of two over-simplifications in the code used in my example... Firstly, the substring property/column (with which I had a problem) applies to a subclass (using joined table inheritance) and the variable to which it applies is specified in its parent class. Hence, I started

Re: [sqlalchemy] Declarative syntax with column_property (v0.6.3)

2010-08-03 Thread Michael Bayer
On Aug 3, 2010, at 7:47 AM, Robert Sudwarts wrote: Hi Michael, I'm guilty of two over-simplifications in the code used in my example... Firstly, the substring property/column (with which I had a problem) applies to a subclass (using joined table inheritance) and the variable to which it

Re: [sqlalchemy] Declarative syntax with column_property (v0.6.3)

2010-08-03 Thread Robert Sudwarts
Please see my comments below. Regards, Rob On 3 August 2010 14:05, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 3, 2010, at 7:47 AM, Robert Sudwarts wrote: Hi Michael, I'm guilty of two over-simplifications in the code used in my example... Firstly, the substring

[sqlalchemy] declarative autoloading table class with composite foreign/primary key

2010-08-03 Thread jgs9000
Hi I'm relatively new to SQLAlchemy, so thanks in advance for any help with this issue. I'm trying to construct a class to model a legacy table which has a composite primary key which is also a composite foreign key referencing the composite primary key of a second table. I'm trying to define

Re: [sqlalchemy] declarative autoloading table class with composite foreign/primary key

2010-08-03 Thread Michael Bayer
On Aug 3, 2010, at 10:24 PM, jgs9000 wrote: Hi I'm relatively new to SQLAlchemy, so thanks in advance for any help with this issue. I'm trying to construct a class to model a legacy table which has a composite primary key which is also a composite foreign key referencing the composite

[sqlalchemy] Declarative syntax with column_property (v0.6.3)

2010-08-02 Thread Robert Sudwarts
Hi, I'm having trouble understanding the correct syntax to be used with Declarative and a column property. The select statement I'm using is: select([func.substr(my_table.c.my_string, 2, 3)]).label(my_substr'), deferred=True And (as per the docs using the expanded syntax, this works as expected.

Re: [sqlalchemy] Declarative syntax with column_property (v0.6.3)

2010-08-02 Thread Michael Bayer
On Aug 2, 2010, at 12:19 PM, Robert Sudwarts wrote: Hi, I'm having trouble understanding the correct syntax to be used with Declarative and a column property. The select statement I'm using is: select([func.substr(my_table.c.my_string, 2, 3)]).label(my_substr'), deferred=True And (as

Re: [sqlalchemy] Declarative syntax with column_property (v0.6.3)

2010-08-02 Thread Michael Bayer
On Aug 2, 2010, at 1:40 PM, Michael Bayer wrote: On Aug 2, 2010, at 12:19 PM, Robert Sudwarts wrote: Hi, I'm having trouble understanding the correct syntax to be used with Declarative and a column property. The select statement I'm using is:

[sqlalchemy] Declarative with mix-in and __table__ fails [patch]

2010-06-04 Thread Gunnlaugur Briem
Hi, if I declaratively map a class with a mix-in and with a __table__ definition that contains the columns in the mix-in, like so: class MyMixin(object): id = Column(Integer, primary_key=True) def foo(self): return 'bar'+str(self.id) class MyModel(Base,MyMixin): __table__ =

Re: [sqlalchemy] Declarative with mix-in and __table__ fails [patch]

2010-06-04 Thread Michael Bayer
On Jun 4, 2010, at 3:21 PM, Gunnlaugur Briem wrote: Hi, if I declaratively map a class with a mix-in and with a __table__ definition that contains the columns in the mix-in, like so: class MyMixin(object): id = Column(Integer, primary_key=True) def foo(self): return

[sqlalchemy] declarative + order_by of 2 columns: is it possible?

2010-05-11 Thread sandro dentella
Hi, i have a working declarative configuration that has a relation as this:: client = relation(Cliente, backref='jobs' , lazy=False, order_by=status.desc) now I'd like to add a second column in the order_by field but adding a list doesn't seem to work. I tried: client = relation(Cliente,

[sqlalchemy] declarative commit hook - onCommit()?

2010-04-28 Thread Daniel Robbins
Hi All, Let's say that when a database record is added or updated, I need to perform some arbitrary action (in my case, ensuring that data in other tables is consistent with what is being committed.) What mechanisms are suggested for this? I could add a save() method to my declarative class that

Re: [sqlalchemy] declarative commit hook - onCommit()?

2010-04-28 Thread Chris Withers
Daniel Robbins wrote: Let's say that when a database record is added or updated, I need to perform some arbitrary action (in my case, ensuring that data in other tables is consistent with what is being committed.) What mechanisms are suggested for this? Mapper extesions:

Re: [sqlalchemy] declarative commit hook - onCommit()?

2010-04-28 Thread Daniel Robbins
On Wed, Apr 28, 2010 at 10:04 AM, Chris Withers ch...@simplistix.co.uk wrote: Daniel Robbins wrote: Let's say that when a database record is added or updated, I need to perform some arbitrary action (in my case, ensuring that data in other tables is consistent with what is being committed.)

RE: [sqlalchemy] declarative commit hook - onCommit()?

2010-04-28 Thread King Simon-NFHD78
Daniel Robbins wrote: On Wed, Apr 28, 2010 at 10:04 AM, Chris Withers ch...@simplistix.co.uk wrote: Daniel Robbins wrote: Let's say that when a database record is added or updated, I need to perform some arbitrary action (in my case, ensuring that data in other tables is

Re: [sqlalchemy] declarative commit hook - onCommit()?

2010-04-28 Thread Daniel Robbins
On Wed, Apr 28, 2010 at 10:25 AM, King Simon-NFHD78 simon.k...@motorola.com wrote: The declarative docs include an example of using a MapperExtension: http://www.sqlalchemy.org/docs/reference/ext/declarative.html#mapper-con figuration Great, thanks for everyone's help. This is exactly the

[sqlalchemy] Declarative mapping and inheritance

2010-04-13 Thread Eagleamon
Hi all, I'm playing around with sqlalchemy for a new project and it's really great :) ... up to now. I'm in front of a problem: let's say I have several classes: class ParameterDefinition(Base): __tablename__ = ParameterDefinitions __table_args__ = {'mysql_engine':'InnoDB'} Type =

Re: [sqlalchemy] Declarative mapping and inheritance

2010-04-13 Thread Michael Bayer
Eagleamon wrote: Hi all, I'm playing around with sqlalchemy for a new project and it's really great :) ... up to now. I'm in front of a problem: let's say I have several classes: class ParameterDefinition(Base): __tablename__ = ParameterDefinitions __table_args__ =

Re: [sqlalchemy] declarative and session

2009-12-27 Thread Serge Koval
You can always do self.session.add(self) in save() without checks. If your model was already associated with the session before, it won't add it again. Here's sample code I use: def save(self, flush=False): self.session.add(self) if flush: self.session.flush() def

[sqlalchemy] declarative and session

2009-12-23 Thread karikris...@gmail.com
I am using declarative style models and very much happy about it. I see __table__ contains the classic sa.Table reference for advanced queries. Like that do we have session is attached to the model class derived from declarative_base? I am very much curious to make django/rail style save,

[sqlalchemy] Declarative, single table inheritance and column type override

2009-12-21 Thread Serge Koval
Hello, I'm trying to override column type in a single-table inheritance, using declarative syntax and a bit stuck. Is it possible at all? Sample code: class Person(DeclarativeBase): id = Column(Integer, primary_key=True) test = Column(Integer, unique=True) class Engineer(Person):

[sqlalchemy] Declarative issues, with compound foreign key

2009-09-15 Thread Gregg Lind
What I think I'm seeing is that an object can be created even without it's ForeignKeyConstraint being filled. To run the test code below: $ dropdb test18; createdb test18; python testcode.py This builds on http://groups.google.com/group/sqlalchemy/browse_thread/thread/eb240f3f2555a5e7/ . I

[sqlalchemy] Declarative base - Joined Table Inheritence

2009-09-15 Thread Jarrod Chesney
Hi All I've been reading the documentation for ages and i can't figure out why when i print the results a query from my inherited table, It just prints them as the base type. I was hoping someone here would be nice enough to help me solve this problem. I thought the last print statement would

[sqlalchemy] : Declarative and association object same model

2009-09-04 Thread Laurent Rahuel
Hi, I need to implement the storage of the neighborood of a place. I try to use Declarative and relation to get this done but it sounds like I missed something important I can not understand. Here are my models: neighbors_table = Table('neighbors', Base.metadata, Column('shop_id',

[sqlalchemy] declarative style many to many, possible fix

2009-09-01 Thread Jae Kwon
Is there a way to declaratively create many to many relationships where the 'secondary' parameter for the relationship is deferred ? I couldn't get this to work, e.g. class User(DeclarativeBase): id = Column(Integer, primary_key=True) name = Column(String(20)) groups =

[sqlalchemy] Declarative way of delete-orphan

2009-08-26 Thread rajasekhar911
Hi How do i define a delete-orphan using declarative base? I am using sqlite and SA0.5.5 I have defined a one to one relation. class Child(DeclarativeBase): __tablename__='children' id=Column(String(50),primary_key=True) parent_id=Column(String(50),ForeignKey

[sqlalchemy] Re: Materialized Path for SQLAlchemy Declarative Base

2009-08-13 Thread Anton Gritsay
Hi, Allen! You can use something like this (yeah, I know that it isn't declarative in any way): class Node(Base): __tablename__ = 'node' id = Column(Integer, primary_key=True) parent_id = Column(ForeignKey('node.id')) parent = relation(Node,

[sqlalchemy] Re: Materialized Path for SQLAlchemy Declarative Base

2009-08-13 Thread allen.fowler
On Aug 13, 2:37 pm, Anton Gritsay gene...@angri.ru wrote: Hi, Allen! You can use something like this (yeah, I know that it isn't declarative in any way):     class Node(Base):         __tablename__ = 'node'         id = Column(Integer, primary_key=True)         parent_id =

[sqlalchemy] Re: Materialized Path for SQLAlchemy Declarative Base

2009-08-13 Thread Michael Bayer
On Aug 13, 2009, at 9:23 PM, allen.fowler wrote: On Aug 13, 2:37 pm, Anton Gritsay gene...@angri.ru wrote: Hi, Allen! You can use something like this (yeah, I know that it isn't declarative in any way): class Node(Base): __tablename__ = 'node' id =

[sqlalchemy] Re: Materialized Path for SQLAlchemy Declarative Base

2009-08-09 Thread allen.fowler
Werner, On Aug 7, 12:36 pm, werner wbru...@free.fr wrote: Allen, allen.fowler wrote: On Aug 6, 6:54 pm, AF allen.fow...@yahoo.com wrote: Hello all, Has anyone here used the sqlamp: Materialized Path for SQLAlchemy library? I am wondering: 1) Does it seem to work well? 2)

[sqlalchemy] Re: Materialized Path for SQLAlchemy Declarative Base

2009-08-07 Thread allen.fowler
On Aug 6, 6:54 pm, AF allen.fow...@yahoo.com wrote: Hello all, Has anyone here used the sqlamp: Materialized Path for SQLAlchemy library? I am wondering: 1) Does it seem to work well? 2) Did you use it with Declarative Base, and if so, how did you configure it? Anybody?

[sqlalchemy] Re: Materialized Path for SQLAlchemy Declarative Base

2009-08-07 Thread werner
Allen, allen.fowler wrote: On Aug 6, 6:54 pm, AF allen.fow...@yahoo.com wrote: Hello all, Has anyone here used the sqlamp: Materialized Path for SQLAlchemy library? I am wondering: 1) Does it seem to work well? 2) Did you use it with Declarative Base, and if so, how did you

[sqlalchemy] Declarative Base: remote_side single_parent

2009-08-06 Thread AF
Hello, What is the correct way to use remote_side single_parent relation parameters under Declarative Base? I'm trying to create an Adjacency List Relationship as suggested in the docs, but I am not sure how to do this with Declarative Base. I tried: children = relation(Node,

[sqlalchemy] Materialized Path for SQLAlchemy Declarative Base

2009-08-06 Thread AF
Hello all, Has anyone here used the sqlamp: Materialized Path for SQLAlchemy library? I am wondering: 1) Does it seem to work well? 2) Did you use it with Declarative Base, and if so, how did you configure it? Thank you, :) --~--~-~--~~~---~--~~ You received

[sqlalchemy] Declarative base and Adjacency List Relationships

2009-08-03 Thread maxi
Hi, I´ve just using sqlalchemy 0.5.1 with python 2.6 and turbogers, but I found a little problem trying to configurate adjacency relationship with declarative base. My object class is something like this: class QueryGroup(DeclarativeBase): __tablename__ = 'queries_group' qry_grp_id =

[sqlalchemy] Declarative, correlated subqueries

2009-07-23 Thread Gregg Lind
I have read over http://www.sqlalchemy.org/docs/05/ormtutorial.html#using-subqueries and http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg11439.html, but I'm having trouble putting the pieces together. In the demo() below, I want to find the row in the database with the max for every

[sqlalchemy] declarative defer error

2009-06-02 Thread quirogaco
Hello, error in declarative query with defer class ClassDefaults(dec.DeclarativeMeta): def __init__(cls, classname, bases, dict_): dict_['id'] = Fdb.Unicode(Adb.Length(55), Adb.Primary_Key(True), Adb.Unique(True), Adb.Nullable(False)) dict_['status'] =

[sqlalchemy] declarative and __table_args__ I must be missing something simple.

2009-04-08 Thread Wayne Witzel
I assume I am over looking some simple thing, but I just can't seem to find it. Thanks for the assist, I have palms open ready for face planting. Using a class and table with orm.mapper() class Child(object): pass child_table = Table('child', meta.metadata, Column('parent_id',

[sqlalchemy] declarative base and association object

2009-02-09 Thread vctr...@gmail.com
Hi, I would like to use an association object with two tables derived from two declarative base classes. What would be (if one may say) the right way to access (get and set) the additional values in the association object? When I set the 2 entities from the base classes and associate them I get

[sqlalchemy] Declarative with Enthoughts Traits framework.

2009-02-07 Thread cputter
Hi guys and girls, I've recently discovered the joys of using sqlalchemy and would love to using it together with Traits. A few months back there was an attempt to integrate sqlalchemy into traits, though it wasn't really comprehensive in exploiting all of sqlalchemy's potential. So I'm trying

[sqlalchemy] Declarative Base ID

2009-02-01 Thread vctr...@gmail.com
The ID field in a declarative base is a sequence that is not controled by the user (or is it?). Is there a way to get it to start the counting of the ID from 0 and not from 1? Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to

[sqlalchemy] Declarative and relation to self

2009-01-06 Thread Gennady Kovalev
Hi! I try to clean up my code, and read in google group about possibility create relation to self when class is not defined yet. I write example, but got an error (see below). My code is: cut engine = create_engine('sqlite:///:memory:', echo=True) Base =

[sqlalchemy] declarative and self-referential table

2008-11-11 Thread MikeCo
I have a table that defines a self-referential hierarchy. My problem is figuring out how to specify that relationship in declarative syntax. From reading the documentation and looking at example basic_tree.py, I think I understand it when using tables and mappers, but can't get it right with

[sqlalchemy] declarative inheritance

2008-11-11 Thread cropr
Does somebody know if is possible to use a declarative class definition for the schema below content = Table('content', meta.metadata, Column('id', types.Integer, primary_key=True, autoincrement=True), Column('title', types.String(80)), Column('parent_id', types.Integer,

[sqlalchemy] Declarative and common fields

2008-09-29 Thread Joril
Hi everyone! I'm new to SQLAlchemy and I'm using version 0.5rc1.. I need every entity class to have a few common fields, so I tried writing an abstract base class, declarative-style, that every other entity class would subclass. So for example: --- from sqlalchemy.ext.declarative import

[sqlalchemy] Re: Problem with coverage and sqlalchemy declarative synonym?

2008-09-19 Thread Michael Bayer
On Sep 18, 2008, at 4:08 PM, Doug Latornell wrote: With some help from Ned Batchelder I was able to confirm that this is a Python bug: http://bugs.python.org/issue1569356 that has been fixed since the 2.5.2 release. Ned confirmed that the fix is included in Python 2.6a3. well

[sqlalchemy] Re: Problem with coverage and sqlalchemy declarative synonym?

2008-09-18 Thread Doug Latornell
With some help from Ned Batchelder I was able to confirm that this is a Python bug: http://bugs.python.org/issue1569356 that has been fixed since the 2.5.2 release. Ned confirmed that the fix is included in Python 2.6a3. Doug On Sep 16, 5:22 pm, Doug Latornell [EMAIL PROTECTED] wrote: Thanks

[sqlalchemy] Declarative documentation

2008-09-16 Thread writeson
Hi all, I'm a new user (like this week) of SqlAlchemy and I'm trying to find more information about using the Declarative system. In particular I'm trying to build a hierarchical table with one-to-many relationships within the table. So if anyone knows where there might be some additional

[sqlalchemy] Problem with coverage and sqlalchemy declarative synonym?

2008-09-16 Thread Doug Latornell
Over on the TurboGears list a TG2 user pointed out a problem that arises when nosetests --with-coverage is run on a project with a sqlalchemy identity model: http://groups.google.com/group/turbogears/t/7fd3639a5a4d4b8c I dug into it and have reproduced the problem outside of TurboGears 2 and

[sqlalchemy] Re: Problem with coverage and sqlalchemy declarative synonym?

2008-09-16 Thread jason kirtland
Doug Latornell wrote: Over on the TurboGears list a TG2 user pointed out a problem that arises when nosetests --with-coverage is run on a project with a sqlalchemy identity model: http://groups.google.com/group/turbogears/t/7fd3639a5a4d4b8c I dug into it and have reproduced the problem

[sqlalchemy] Re: Problem with coverage and sqlalchemy declarative synonym?

2008-09-16 Thread Michael Bayer
On Sep 16, 2008, at 7:25 PM, Doug Latornell wrote: Over on the TurboGears list a TG2 user pointed out a problem that arises when nosetests --with-coverage is run on a project with a sqlalchemy identity model: http://groups.google.com/group/turbogears/t/7fd3639a5a4d4b8c I dug into it and

[sqlalchemy] Re: Problem with coverage and sqlalchemy declarative synonym?

2008-09-16 Thread Doug Latornell
Thanks for the quick replies, Jason and Michael, and for the very succinct test case. I will try to raise this with Ned Bachelor over at http://nedbatchelder.com/code/modules/coverage.html Doug On Sep 16, 4:55 pm, Michael Bayer [EMAIL PROTECTED] wrote: On Sep 16, 2008, at 7:25 PM, Doug

[sqlalchemy] declarative

2008-08-19 Thread Jose Galvez
What is the proposed stability of declarative functions which I guess are pretty new. From what I've read so far I really like it and was thinking of using it, but was just wondering what the long turn outlook for it looked like? After doing some reading on the new release of Elixir, Elixir

[sqlalchemy] Declarative 0.5 tutorial fails to create tables before insert

2008-07-17 Thread Kris Kennaway
Hi, I'm trying to follow the declarative example in the tutorial with 0.5.0b2, and it's failing to work: from sqlalchemy import create_engine engine = create_engine('sqlite:///:memory:', echo=True) from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey from

<    1   2