[sqlalchemy] allow_column_override

2008-05-15 Thread Chris Guin
My goal is to have a one-to-many relation defined using the same name 
as the foreign key column underneath.  So that, if my Detection 
table has a foreignkey column named sensor, the following mappers 
should work, I think:

mapper(Sensor, sensor)
detectionmapper = mapper(Detection, detection, 
allow_column_override=True, properties={
 'sensor': relation(Sensor),
})

I'm getting the following exception, however, when I actually create 
a Detection with a Sensor and try to flush the session:

Traceback (most recent call last):
   File console, line 1, in module
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\scoping.py,
 
line 98, in do
 return getattr(self.registry(), name)(*args, **kwargs)
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\session.py,
 
line 757, in flush
 self.uow.flush(self, objects)
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\unitofwork.py,
 
line 233, in flush
 flush_context.execute()
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\unitofwork.py,
 
line 445, in execute
 UOWExecutor().execute(self, tasks)
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\unitofwork.py,
 
line 930, in execute
 self.execute_save_steps(trans, task)
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\unitofwork.py,
 
line 948, in execute_save_steps
 self.execute_dependencies(trans, task, False)
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\unitofwork.py,
 
line 959, in execute_dependencies
 self.execute_dependency(trans, dep, False)
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\unitofwork.py,
 
line 942, in execute_dependency
 dep.execute(trans, isdelete)
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\unitofwork.py,
 
line 895, in execute
 self.processor.process_dependencies(self.targettask, [elem.state 
for elem in self.targettask.polymorphic_tosave_elements if elem
.state is not None], trans, delete=False)
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\dependency.py,
 
line 332, in process_dependencies
 self._synchronize(state, child, None, False, uowcommit)
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\dependency.py,
 
line 374, in _synchronize
 sync.populate(child, self.mapper, state, self.parent, 
self.prop.synchronize_pairs)
   File 
c:\python25\lib\site-packages\SQLAlchemy-0.4.5-py2.5.egg\sqlalchemy\orm\sync.py,
 
line 27, in populate
 self._raise_col_to_prop(True, source_mapper, l, dest_mapper, r)
NameError: global name 'self' is not defined


I am still using SQLAlchemy 0.4.5.

Thanks for any help!
Chris 
--~--~-~--~~~---~--~~
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: Multiple Levels of Inheritance

2008-03-28 Thread Chris Guin

Thanks!  That appears to have done it.

Chris Guin

At 05:28 PM 3/27/2008, you wrote:


On Mar 27, 2008, at 3:54 PM, Chris Guin wrote:

 
  Does anyone know where I could find a working example of multiple
  levels of inheritance using joined table inheritance?
 
  Right now I have the following class hierarchy - an AspectDetection
  and an RFDetection are subclasses of Detection, which in turn is a
  subclass of Event.  Each of the classes has its own DB table, and an
  object can be simply an Event or a Detection.  I've tried mapping
  these classes together using the following code:
 
  detection_join =
  detection.outerjoin(aspect_detection).outerjoin(rf_detection)
  event_join = detection_join.outerjoin(event)

if the ultimate base class is Event, then the event table's columns
must be present in every result set.  By outerjoining (where outerjoin
is a LEFT OUTER JOIN) detection to event, you dont get Event objects
that are not Detection objects.  So event join should be:

 event_join=event.outerjoin(detection_join)

Similarly, mapping select_table directly to detection_join for
detection_mapper does not include any columns from the Event table, so
those loads would be failing pretty badly.   So for that mapper,
assuming you want all subclasses in one big query, youd want to set
select_table to:


event
.outerjoin
(detection).outerjoin(aspect_detection).outerjoin(rf_detection)

the good news is, 0.4.5 will deprecate select_table and you'll just be
able to say with_polymorphic='*' on all your mappers where you want
a join of all subtables constructed by default - it will do all this
work for you.





--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---