Hello,

I am attempting to implement a relationship accross two MSSQL databases 
that may or may not be on the samer server.  The catch is that MSSQL does 
not support cross database forgien key contraints (the tables must be in 
the same db).

I am trying to to implement the relationship with a pimary join as follows:

class Simulated_Event(Base):

    __tablename__ = 'Simulated_Events'
    
    sim = Column(Integer, primary_key = True, autoincrement = False)
    event_id = Column(Integer, primary_key = True, autoincrement = False)

   Simulation_Catalog_Full_Table_Name = 
'ServerName.Temp_DB.dbo.Simulation_Catalog_Table'

   catalog_event = relationship('Catalog_Event', 
 backref=backref('simulated_event'), 
foreign_keys=[Simulation_Catalog_Full_Table_Name+'.Sims', 
Simulation_Catalog_Full_Table_Name+'.EventID'], 
                                 primaryjoin ='Simulated_Events.sim = 
'+Simulation_Catalog_Full_Table_Name+'.Sims and Simulated_Events.event_id = 
'+Simulation_Catalog_Full_Table_Name+'.EventID')

#Sims and EventID are columns in the Simulation_Catalog_Table table.

When I run this, I get the following message:

  File "C:\Python27\lib\site-packages\sqlalchemy\orm\scoping.py", line 70, 
in __call__
    return self.registry()
  File "C:\Python27\lib\site-packages\sqlalchemy\util\_collections.py", 
line 886, in __call__
    val = self.registry.value = self.createfunc()
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\session.py", line 
2241, in __call__
    return self.class_(**local_kw)
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\session.py", line 609, 
in __init__
    self.bind_mapper(mapperortable, bind)
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\session.py", line 988, 
in bind_mapper
    mapper = class_mapper(mapper)
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\util.py", line 1112, 
in class_mapper
    mapper = _inspect_mapped_class(class_, configure=configure)
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\util.py", line 1045, 
in _inspect_mapped_class
    mapperlib.configure_mappers()
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\mapper.py", line 2121, 
in configure_mappers
    mapper._post_configure_properties()
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\mapper.py", line 1243, 
in _post_configure_properties
    prop.init()
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\interfaces.py", line 
231, in init
    self.do_init()
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\properties.py", line 
1027, in do_init
    self._process_dependent_arguments()
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\properties.py", line 
1050, in _process_dependent_arguments
    setattr(self, attr, attr_value())
  File 
"C:\Python27\lib\site-packages\sqlalchemy\ext\declarative\clsregistry.py", 
line 252, in return_cls
    x = eval(arg, globals(), d)
  File "<string>", line 1
    Simulated_Events.sim 
= ServerName.Temp_DB.dbo.Simulation_Catalog_Table.Sims and 
Simulated_Events.event_id 
= ServerName.Temp_DB.dbo.Simulation_Catalog_Table.EventID
                         ^
SyntaxError: invalid syntax

I've run the string in the console and they are concatenating correctly, 
what is the source of the sytax error?  Is SQLAlchemy parsing the string 
and trying to determine something?  I would expected it to just drop the 
string into the join as run time.

Any general adive about complex or multi-database relationship 
configuration would also be appreciated :)

Thank you for your help and advice,

~Victor

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to