[sqlalchemy] Re: refresh(object)

2008-05-10 Thread Werner F. Bruhin

Michael,

Thanks for the quick reply, I needed a bit of time to be able to get 
some more data on this.

Michael Bayer wrote:
 ...
 uh it depends on what object.otherviewofsubobject is...is that a  
 relation() ?  a python descriptor ?  if the latter, how does it  
 work ?  where does it get context from ?   seems like this is a simple  
 issue of issuing a SELECT on a connection outside of the current  
 transaction.
   
They are both relation.  Ok, here some test code showing the problem, I 
hope this will allow you to give me some pointers.

consevent = session.query(db.consevent).get(1)
conseventMU = consevent.conseventmu
conseventMUview = consevent.vconseventmu
print 'conseventmu'
for item in conseventMU:
print item
print 'conseventmu-VIEW'
for item in conseventMUview:
print item


consItem = session.query(db.conseventmu).get(5)
consItem.description = uSouris d'ageau

session.flush()
session.refresh(consevent)
##consevent = session.query(db.consevent).get(1)  # this does not work 
either
conseventMU = consevent.conseventmu
conseventMUview = consevent.vconseventmu
print 'conseventmu'
for item in conseventMU:
print item
print 'conseventmu-VIEW'
for item in conseventMUview:
print item

Sample output - before update:

conseventmu
...
Conseventmu(conseventmuid=5, description=uSouris d'agneau 
aaa23355bbbxx, created=datetime.date(2008, 5, 7), 
updated=datetime.date(2008, 5, 7), fk_conseventid=1, fk_ingrid=None, 
fk_recipeid=2, fk_courseid=6, fk_cbbottleid=None)
...
conseventmu-VIEW
...
Vconseventmu(conseventmuid=5, name=u'Foie Gras aux Epices', 
itemtype=u'R   ', description=uSouris d'agneau aaa23355bbbxx, 
created=datetime.date(2008, 5, 7), updated=datetime.date(2008, 5, 7), 
fk_conseventid=1, fk_ingrid=None, fk_recipeid=2, fk_courseid=6, 
fk_cbbottleid=None)
...

Sample output - after update and flush:
conseventmu
...
Conseventmu(conseventmuid=5, description=uSouris d'ageau, 
created=datetime.date(2008, 5, 7), updated=datetime.date(2008, 5, 7), 
fk_conseventid=1, fk_ingrid=None, fk_recipeid=2, fk_courseid=6, 
fk_cbbottleid=None)
...
conseventmu-VIEW
...
Vconseventmu(conseventmuid=5, name=u'Foie Gras aux Epices', 
itemtype=u'R   ', description=uSouris d'agneau aaa23355bbbxx, 
created=datetime.date(2008, 5, 7), updated=datetime.date(2008, 5, 7), 
fk_conseventid=1, fk_ingrid=None, fk_recipeid=2, fk_courseid=6, 
fk_cbbottleid=None)
...

Some of my model (I hope I provide the relevant parts you need to be 
able to help me)- keep in mind that Vconseventmu is a FB view and not a 
real table (this is used mainly to show items in listctrl's in my 
wxPython application - there are no updates to it).

consevent = sao.mapper(Consevent, consevent_table,
properties={
...
'conseventmu': sao.relation(Conseventmu),
'vconseventmu': sao.relation(Vconseventmu) #, 
enable_typechecks=False),
})

conseventmu = sao.mapper(Conseventmu, conseventmu_table,
properties={
...
'recipe': sao.relation(Recipe),
'ingr_ls': sao.relation(Ingr_Ls),
'consevent': sao.relation(Consevent),
})

vconseventmu = sao.mapper(Vconseventmu, vconseventmu_table,
properties={
...
'ingr_ls': sao.relation(Ingr_Ls),
'recipe': sao.relation(Recipe),
'consevent': sao.relation(Consevent),
})

vconseventmu_table = sa.Table(u'vconseventmu', metadata,
sa.Column(u'conseventmuid', sa.Integer(), 
sa.ForeignKey(u'conseventmu.conseventmuid'), primary_key=True), # fake
sa.Column(u'name', sa.String(length=50, convert_unicode=False)),
sa.Column(u'itemtype', sa.String(length=1, convert_unicode=False)),
sa.Column(u'description', sa.String(length=50, convert_unicode=False)),
sa.Column(u'created', sa.Date()),
sa.Column(u'updated', sa.Date()),
sa.Column(u'fk_conseventid', sa.Integer(), 
sa.ForeignKey(u'consevent.conseventid')),
sa.Column(u'fk_ingrid', sa.Integer(), sa.ForeignKey(u'ingr_ls.ingrid')),
sa.Column(u'fk_recipeid', sa.Integer(), 
sa.ForeignKey(u'recipe.recipeid')),
sa.Column(u'fk_courseid', sa.Integer(), 
sa.ForeignKey(u'course_ls.courseid')),
sa.Column(u'fk_cbbottleid', sa.Integer(), 
sa.ForeignKey(u'cbbottle.cbbottleid')),
)

consevent_table = sa.Table(u'consevent', metadata,
sa.Column(u'conseventid', sa.Integer(), 
sa.Sequence('gen_consevent_conseventid'), primary_key=True, nullable=False),
sa.Column(u'description', sa.String(length=25, convert_unicode=False)),
sa.Column(u'conseventdate', sa.DateTime(timezone=False)),
sa.Column(u'fk_reasonid', sa.Integer(), 
sa.ForeignKey(u'reason_ls.reasonid')),
sa.Column(u'created', sa.Date()),
sa.Column(u'updated', sa.Date()),
sa.Column(u'notes', sa.TEXT(length=32000, convert_unicode=True)),
)

DDL for FB view:
CREATE VIEW VCONSEVENTMU(
CONSEVENTMUID,
NAME,
ITEMTYPE,
DESCRIPTION,
CREATED,
UPDATED,
FK_CONSEVENTID,
FK_INGRID,
FK_RECIPEID,
FK_COURSEID,
FK_CBBOTTLEID)
AS
select item.conseventmuid,
   

[sqlalchemy] Defining common columns for a group of tables

2008-05-10 Thread Sandesh Singh

Hi.

I want to add a set of common columns for a set of tables. For
example, given tables

personal_profile(name, nickname, fav_color ...)
professional_profile(work, location, designation ...)

I want to add auditing columns to both of these, like so -

personal_profile(*created_on*, *updated_on*, name, nickname, fav_color ...)
professional_profile(*created_on*, *updated_on*, work, location,
designation ...)

It would be best if the auditing columns could be defined in one
place, and then added to all the tables individually. I believe the
solution may have more to do with Python than with SQLAlchemy itself.

Thanks.

-- 
sss
http://sandesh247.googlepages.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Defining common columns for a group of tables

2008-05-10 Thread Lele Gaifax

On Sat, 10 May 2008 14:06:12 +0530
Sandesh Singh [EMAIL PROTECTED] wrote:

 It would be best if the auditing columns could be defined in one
 place, and then added to all the tables individually. I believe the
 solution may have more to do with Python than with SQLAlchemy itself.

This is my solution to that very same problem:

def addTimestamp(table):
table.append_column(Column('rec_creato', timestamp_t))
table.append_column(Column('rec_creato_da', username_t))
table.append_column(Column('rec_modificato', timestamp_t))
table.append_column(Column('rec_modificato_da', username_t))

...

mytable = Table('mytable', metadata,
Column('id, smallid_t, primary_key=True),
...
)
addTimestamp(mytable)

I use Postgres, and all my tables inherits from a timestamped
abstract table that contains those fields. I did try to use an
equivalent setup also for the SA definition, by subclassing
Table... but ran into strange issues: a demo session was getting
closer, so I went for the above solution.

I have another little issue with that: I'd like to be able to say that
those fields behave like a readonly and database-generated value (they
are effectively overwritten by a database trigger, at insert/update
time), possibly without resorting to marking them defer on each
mapped entity... Any magical shortcut to achieve that? :-)

hth,
ciao, lele.
-- 
nickname: Lele Gaifax| Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas| comincerò ad aver paura di chi mi copia.
[EMAIL PROTECTED] | -- Fortunato Depero, 1929.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Defining common columns for a group of tables

2008-05-10 Thread Michael Bayer


On May 10, 2008, at 10:01 AM, Lele Gaifax wrote:


 I have another little issue with that: I'd like to be able to say that
 those fields behave like a readonly and database-generated value (they
 are effectively overwritten by a database trigger, at insert/update
 time), possibly without resorting to marking them defer on each
 mapped entity... Any magical shortcut to achieve that? :-)


yeah put a PassiveDefault on each of them.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Combining joined and single table inheritance

2008-05-10 Thread Michael Bayer

seems like a bug whereby when it sees the Manager single table  
inheritor, it somehow doesn't get the message to synchronize the  
Employee primary key column with the Person primary key column.   
I'll have a look at it later today.


On May 9, 2008, at 7:49 PM, Fernando Zunino wrote:


 Hi,
 is it possible to combine joined and single table inheritance in the
 same inheritance hierarchy?

 In the code at the bottom I want to use the persons table as a base
 for the Person, Employee and Manager classes and the employees table
 to store the particular fields of Employee and Manager.

 I've run this code using PostgreSql and it correctly flushes the
 Person and Employee instances but when it wants to flush the Manager
 instance gives the following error:

 /home/fernando/.pythonrepo/SQLAlchemy-0.4.5-py2.5.egg/sqlalchemy/
 engine/base.py in _handle_dbapi_exception(self, e, statement,
 parameters, cursor)
940 if self.__close_with_result:
941 self.close()
 -- 942 raise exceptions.DBAPIError.instance(statement,
 parameters, e, connection_invalidated=is_disconnect)
943 finally:
944 del self._reentrant_error

 class 'sqlalchemy.exceptions.ProgrammingError': (ProgrammingError)
 relation employees_person_id_seq does not exist
 'select nextval(\'employees_person_id_seq\')' None

 Anyone have any suggestions?

 thanks,
 Fernando


 class Person(object):
def __init__(self, name):
self.name = name
def __repr__(self):
return self.__class__.__name__ +   + self.name

 class Employee(Person):
def __init__(self, name, employee_data):
self.name = name
self.employee_data = employee_data

def __repr__(self):
return self.__class__.__name__ +   + self.name +   +
 self.employee_data

 class Manager(Employee):
def __init__(self, name, employee_data, manager_data):
self.name = name
self.employee_data = employee_data
self.manager_data = manager_data

def __repr__(self):
return self.__class__.__name__ +   + self.name +   +
 self.manager_data

 persons_table = Table('persons', metadata,
Column('person_id', Integer, primary_key=True),
Column('name', String(50)),
Column('type', String(20), nullable=False)
 )

 employees_table = Table('employees', metadata,
Column('person_id', Integer, ForeignKey('persons.person_id'),
 primary_key=True),
Column('employee_data', String(50)),
Column('manager_data', String(50)),
 )

 person_mapper = mapper(Person, persons_table, \
polymorphic_on=persons_table.c.type,
 polymorphic_identity='person')
 employee_mapper = mapper(Employee, employees_table, inherits=Person,
 polymorphic_identity='engineer')
 manager_mapper = mapper(Manager, inherits=employee_mapper,
 polymorphic_identity='manager')

 metadata.create_all(engine);
 Session = scoped_session(sessionmaker(bind=engine, autoflush=True,
 transactional=True))
 session = Session();

 session.save(Person('fer'))
 session.save(Employee('e', 'e1'))
 session.save(Manager('m', 'e2', 'm1'))
 session.flush()



 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Query objects and empty slices

2008-05-10 Thread Michael Bayer


On May 10, 2008, at 10:22 AM, Yannick Gingras wrote:

 I attach a test case.  In here, it prints:

 --
 ** q[:0]
 SELECT users.id AS users_id, users.name AS users_name
 FROM users ORDER BY users.id


 ** q[0:0]
 SELECT users.id AS users_id, users.name AS users_name
 FROM users ORDER BY users.id


 ** q[1:1]
 SELECT users.id AS users_id, users.name AS users_name
 FROM users ORDER BY users.id
 LIMIT 0 OFFSET 1


 ** q[0:10]
 SELECT users.id AS users_id, users.name AS users_name
 FROM users ORDER BY users.id
 LIMIT 10 OFFSET 0
 --

 Shouldn't the first two feature  LIMIT 0 OFFSET 1?

yes.  but the question was, limit is ignored when offset is zero,  
which is not the issue.  LIMIT is ignored when its zero, period (it  
evaluates to false).  the decision to be made is, should Query  
circumvent querying altogether when limit is zero.   this will be easy  
to fix in 0.5 since slices will no longer be generative, so we'll just  
return an empty iterator.  ticket 1035 in trac.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Combining joined and single table inheritance

2008-05-10 Thread Michael Bayer

very simple and was fixed in r4720.


On May 10, 2008, at 12:48 PM, Michael Bayer wrote:


 seems like a bug whereby when it sees the Manager single table
 inheritor, it somehow doesn't get the message to synchronize the
 Employee primary key column with the Person primary key column.
 I'll have a look at it later today.


 On May 9, 2008, at 7:49 PM, Fernando Zunino wrote:


 Hi,
 is it possible to combine joined and single table inheritance in the
 same inheritance hierarchy?

 In the code at the bottom I want to use the persons table as a base
 for the Person, Employee and Manager classes and the employees table
 to store the particular fields of Employee and Manager.

 I've run this code using PostgreSql and it correctly flushes the
 Person and Employee instances but when it wants to flush the Manager
 instance gives the following error:

 /home/fernando/.pythonrepo/SQLAlchemy-0.4.5-py2.5.egg/sqlalchemy/
 engine/base.py in _handle_dbapi_exception(self, e, statement,
 parameters, cursor)
   940 if self.__close_with_result:
   941 self.close()
 -- 942 raise exceptions.DBAPIError.instance(statement,
 parameters, e, connection_invalidated=is_disconnect)
   943 finally:
   944 del self._reentrant_error

 class 'sqlalchemy.exceptions.ProgrammingError': (ProgrammingError)
 relation employees_person_id_seq does not exist
 'select nextval(\'employees_person_id_seq\')' None

 Anyone have any suggestions?

 thanks,
 Fernando


 class Person(object):
   def __init__(self, name):
   self.name = name
   def __repr__(self):
   return self.__class__.__name__ +   + self.name

 class Employee(Person):
   def __init__(self, name, employee_data):
   self.name = name
   self.employee_data = employee_data

   def __repr__(self):
   return self.__class__.__name__ +   + self.name +   +
 self.employee_data

 class Manager(Employee):
   def __init__(self, name, employee_data, manager_data):
   self.name = name
   self.employee_data = employee_data
   self.manager_data = manager_data

   def __repr__(self):
   return self.__class__.__name__ +   + self.name +   +
 self.manager_data

 persons_table = Table('persons', metadata,
   Column('person_id', Integer, primary_key=True),
   Column('name', String(50)),
   Column('type', String(20), nullable=False)
 )

 employees_table = Table('employees', metadata,
   Column('person_id', Integer, ForeignKey('persons.person_id'),
 primary_key=True),
   Column('employee_data', String(50)),
   Column('manager_data', String(50)),
 )

 person_mapper = mapper(Person, persons_table, \
   polymorphic_on=persons_table.c.type,
 polymorphic_identity='person')
 employee_mapper = mapper(Employee, employees_table, inherits=Person,
 polymorphic_identity='engineer')
 manager_mapper = mapper(Manager, inherits=employee_mapper,
 polymorphic_identity='manager')

 metadata.create_all(engine);
 Session = scoped_session(sessionmaker(bind=engine, autoflush=True,
 transactional=True))
 session = Session();

 session.save(Person('fer'))
 session.save(Employee('e', 'e1'))
 session.save(Manager('m', 'e2', 'm1'))
 session.flush()






 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] trunk is now on 0.5

2008-05-10 Thread Michael Bayer

hey list -

as you might have noticed we've merged 0.5 into the trunk.   this  
version is already spectacular and I encourage everyone to start  
poking around.

The migration doc is being developed at 
http://www.sqlalchemy.org/trac/wiki/05Migration 
  .  The emphasis in this release is two big new paradigm shifts (i'll  
leave what those are as an exercise for the reader), honing in on a  
particular set of defaults for things (i.e. sessions), and otherwise  
locking down lots of APIs that were in a previously wiggly or  
otherwise deprecated state.

Two controversies to settle are:

-  Python 2.3.  We'd *really* like to get off of it as it holds us  
back from working more nicely with 2.6 as well as the 2to3 tool.
 -  Unicode.   Consideration of going further into being  
unicode everywhere, which may or may not impact end-user code (i.e.  
if you use String, you need to send u'hello' for data)

For access to the current trunk of 0.4, we're back on the 0.4 branch:

http://svn.sqlalchemy.org/sqlalchemy/branches/rel_0_4

Next release of 0.4 is 0.4.6 which should be out soon.




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: trunk is now on 0.5

2008-05-10 Thread Mike Bernson

Is the stuff from user_defined_state branch merge in ?

If so is the  __sa_instrument_class__ stuff the same ?

Michael Bayer wrote:
 hey list -
 
 as you might have noticed we've merged 0.5 into the trunk.   this  
 version is already spectacular and I encourage everyone to start  
 poking around.
 
 The migration doc is being developed at 
 http://www.sqlalchemy.org/trac/wiki/05Migration 
   .  The emphasis in this release is two big new paradigm shifts (i'll  
 leave what those are as an exercise for the reader), honing in on a  
 particular set of defaults for things (i.e. sessions), and otherwise  
 locking down lots of APIs that were in a previously wiggly or  
 otherwise deprecated state.
 
 Two controversies to settle are:
 
   -  Python 2.3.  We'd *really* like to get off of it as it holds us  
 back from working more nicely with 2.6 as well as the 2to3 tool.
  -  Unicode.   Consideration of going further into being  
 unicode everywhere, which may or may not impact end-user code (i.e.  
 if you use String, you need to send u'hello' for data)
 
 For access to the current trunk of 0.4, we're back on the 0.4 branch:
 
 http://svn.sqlalchemy.org/sqlalchemy/branches/rel_0_4
 
 Next release of 0.4 is 0.4.6 which should be out soon.
 
 
 
 
  

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: trunk is now on 0.5

2008-05-10 Thread Steve Zatz

Trunk Rev 4726

Note the following:

Python 2.5.2 (r252:60911, May  7 2008, 15:19:09)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type help, copyright, credits or license for more information.
 from sqlalchemy import *
Traceback (most recent call last):
  File stdin, line 1, in module
  File .../sqlalchemy/__init__.py, line 34, in module
from sqlalchemy.engine import create_engine, engine_from_config
  File .../sqlalchemy/engine/__init__.py, line 54, in module
from sqlalchemy.engine.base import Dialect, ExecutionContext, Compiled, \
  File .../sqlalchemy/engine/base.py, line 16, in module
from sqlalchemy import exc, schema, util, types, log
  File .../sqlalchemy/log.py, line 35, in module
rootlogger = logging.getLogger('sqlalchemy')
AttributeError: 'module' object has no attribute 'getLogger'


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: trunk is now on 0.5

2008-05-10 Thread jason kirtland

Steve Zatz wrote:
 Trunk Rev 4726
 
 Note the following:
 
 Python 2.5.2 (r252:60911, May  7 2008, 15:19:09)
 [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
 Type help, copyright, credits or license for more information.
 from sqlalchemy import *
 Traceback (most recent call last):
   File stdin, line 1, in module
   File .../sqlalchemy/__init__.py, line 34, in module
 from sqlalchemy.engine import create_engine, engine_from_config
   File .../sqlalchemy/engine/__init__.py, line 54, in module
 from sqlalchemy.engine.base import Dialect, ExecutionContext, Compiled, \
   File .../sqlalchemy/engine/base.py, line 16, in module
 from sqlalchemy import exc, schema, util, types, log
   File .../sqlalchemy/log.py, line 35, in module
 rootlogger = logging.getLogger('sqlalchemy')
 AttributeError: 'module' object has no attribute 'getLogger'

Some modules have moved around for 0.5.  If you're updating an exsiting 
trunk check out, be sure to clean out the .pyc files.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Combining joined and single table inheritance

2008-05-10 Thread Fernando Zunino

Thanks!!

On May 10, 2:42 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 very simple and was fixed in r4720.

 On May 10, 2008, at 12:48 PM, Michael Bayer wrote:



  seems like a bug whereby when it sees the Manager single table
  inheritor, it somehow doesn't get the message to synchronize the
  Employee primary key column with the Person primary key column.
  I'll have a look at it later today.

  On May 9, 2008, at 7:49 PM, Fernando Zunino wrote:

  Hi,
  is it possible to combine joined and single table inheritance in the
  same inheritance hierarchy?

  In the code at the bottom I want to use the persons table as a base
  for the Person, Employee and Manager classes and the employees table
  to store the particular fields of Employee and Manager.

  I've run this code using PostgreSql and it correctly flushes the
  Person and Employee instances but when it wants to flush the Manager
  instance gives the following error:

  /home/fernando/.pythonrepo/SQLAlchemy-0.4.5-py2.5.egg/sqlalchemy/
  engine/base.py in _handle_dbapi_exception(self, e, statement,
  parameters, cursor)
940 if self.__close_with_result:
941 self.close()
  -- 942 raise exceptions.DBAPIError.instance(statement,
  parameters, e, connection_invalidated=is_disconnect)
943 finally:
944 del self._reentrant_error

  class 'sqlalchemy.exceptions.ProgrammingError': (ProgrammingError)
  relation employees_person_id_seq does not exist
  'select nextval(\'employees_person_id_seq\')' None

  Anyone have any suggestions?

  thanks,
  Fernando

  class Person(object):
def __init__(self, name):
self.name = name
def __repr__(self):
return self.__class__.__name__ +   + self.name

  class Employee(Person):
def __init__(self, name, employee_data):
self.name = name
self.employee_data = employee_data

def __repr__(self):
return self.__class__.__name__ +   + self.name +   +
  self.employee_data

  class Manager(Employee):
def __init__(self, name, employee_data, manager_data):
self.name = name
self.employee_data = employee_data
self.manager_data = manager_data

def __repr__(self):
return self.__class__.__name__ +   + self.name +   +
  self.manager_data

  persons_table = Table('persons', metadata,
Column('person_id', Integer, primary_key=True),
Column('name', String(50)),
Column('type', String(20), nullable=False)
  )

  employees_table = Table('employees', metadata,
Column('person_id', Integer, ForeignKey('persons.person_id'),
  primary_key=True),
Column('employee_data', String(50)),
Column('manager_data', String(50)),
  )

  person_mapper = mapper(Person, persons_table, \
polymorphic_on=persons_table.c.type,
  polymorphic_identity='person')
  employee_mapper = mapper(Employee, employees_table, inherits=Person,
  polymorphic_identity='engineer')
  manager_mapper = mapper(Manager, inherits=employee_mapper,
  polymorphic_identity='manager')

  metadata.create_all(engine);
  Session = scoped_session(sessionmaker(bind=engine, autoflush=True,
  transactional=True))
  session = Session();

  session.save(Person('fer'))
  session.save(Employee('e', 'e1'))
  session.save(Manager('m', 'e2', 'm1'))
  session.flush()
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: trunk is now on 0.5

2008-05-10 Thread Steve Zatz

  be sure to clean out the .pyc files.
That worked. Thanks.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---