Hi! How are you doing today?
I'm writing because I have a database problem. I am trying to migrate a Grok/Zope application from ZopeDB to MySql, and I don't know exactly how to specify one of the relationships between tables... I am using “megrok.rdb” and “sqlalchemy”.
I have four classes involved:
A record with some information (let's say name and address of people)
A class that can store records of the aforesaid type (it's basically a class that behaves as a list)
A “manager” that has some other information and two of instances of the class who stores entries (two lists)
An “external” (external to all this assembly) class that uses one of these managers.
For the example, the external class looks like:
class External(rdb.Model):
rdb.metadata(metadata)
rdb.tablename("externals")
id = Column("id", Integer, primary_key=True)
title = Column("title", String(100))
moreStuff = Column("more_stuff", Integer(unsigned=True))
entryManager = relationship("EntryManager", secondary="entry_managers"")
And then:
class Entry(rdb.Model):
rdb.metadata(metadata)
rdb.tablename("entries")
id=Column("id", Integer, primary_key=True)
name = Column("name", String(16))
address = Column("address", String(16))
def __init__(self):
self.data = “hello”
class EntryContainer( ? ? ? ):
#I really don't know very well what to do with this
def __init__(self):
self.__list = list()
class EntryManager(rdb.Model):
rdb.metadata(metadata)
rdb.tablename("entry_managers")
id=Column("id", Integer, primary_key=True)
myOtherStuff = Column("my_other_stuff", String(16))
containerA = EntryContainer()
containerB = EntryContainer()
My guess is that I don't really need the EntryContainer to be a rdb.Model. It could just be an intermediate table of the type [id, id_of_entry].
How can I tell to the system that containerA and containerB have to use that “intermediate” table?. I tried something like:
entries_container = Table(
"entries_container",
metadata,
Column("id", Integer, primary_key=True),
Column("entry_id", Integer, ForeignKey("backup_entries.id"))
)
class EntryManager(rdb.Model):
rdb.metadata(metadata)
rdb.tablename("entry_managers")
id=Column("id", Integer, primary_key=True)
myOtherStuff = Column("my_other_stuff", String(16))
containerA = relationship("Entry", secondary="entries_container", backref="backup_entries")
containerB = relationship("Entry", secondary="entries_container", backref="backup_entries")
but I am not capable of using containerA and containerB as a regular list() object... Something is failing. When I try to set up the tables it says:
ArgumentError: Could not determine join condition between parent/child tables on relationship EntryManager.containerA. Specify a 'primaryjoin' expression. If 'secondary' is present, 'secondaryjoin' is needed as well.
Thank you very much