Hi! How are you doing today?<br><br>I&#39;m writing because I have a database problem. I am trying to migrate a Grok/Zope application from ZopeDB to MySql, and I don&#39;t know exactly how to specify one of the relationships between tables... I am using “megrok.rdb” and “sqlalchemy”.<br>

<br>I have four classes involved:<br><ol><li>A record with some information (let&#39;s say name and address of people)</li><li>A class that can store records of the aforesaid type (it&#39;s basically a class that behaves as a list)</li>

<li>A “manager” that has some other information and two of instances of the class who stores entries (two lists)</li><li>An “external” (external to all this assembly) class that uses one of these managers.</li></ol><br>For the example, the external class looks like:<br>

<br><span style="font-family: courier new,monospace;">class External(rdb.Model):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    rdb.metadata(metadata)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    rdb.tablename(&quot;externals&quot;)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    id = Column(&quot;id&quot;, Integer, primary_key=True)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    title = Column(&quot;title&quot;, String(100))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    moreStuff = Column(&quot;more_stuff&quot;, Integer(unsigned=True))</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    entryManager = relationship(&quot;EntryManager&quot;, secondary=&quot;entry_managers&quot;&quot;)</span><br><br>And then:<br><br><span style="font-family: courier new,monospace;">class Entry(rdb.Model):</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    rdb.metadata(metadata)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    rdb.tablename(&quot;entries&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    id=Column(&quot;id&quot;, Integer, primary_key=True)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    name = Column(&quot;name&quot;, String(16))</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    address = Column(&quot;address&quot;, String(16))</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    def __init__(self):</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        self.data = “hello”</span><br><br><span style="font-family: courier new,monospace;">class EntryContainer( ? ? ? ):</span><br style="font-family: courier new,monospace;">

<i><span style="font-family: courier new,monospace;">    #I really don&#39;t know very well what to do with this</span></i><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    def __init__(self):</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        self.__list = list()</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">class EntryManager(rdb.Model):</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    rdb.metadata(metadata)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    rdb.tablename(&quot;entry_managers&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    id=Column(&quot;id&quot;, Integer, primary_key=True)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    myOtherStuff = Column(&quot;my_other_stuff&quot;, String(16))</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    containerA = EntryContainer()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    containerB = EntryContainer()</span><br>

<br>My guess is that I don&#39;t really need the EntryContainer to be a<br>rdb.Model. It could just be an intermediate table of the type [id,<br>id_of_entry].<br><br>How can I tell to the system that containerA and containerB have to<br>

use that “intermediate” table?. I tried something like:<br><br><span style="font-family: courier new,monospace;">entries_container = Table(</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    &quot;entries_container&quot;,</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    metadata,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    Column(&quot;id&quot;, Integer, primary_key=True),</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    Column(&quot;entry_id&quot;, Integer, ForeignKey(&quot;<a href="http://backup_entries.id">backup_entries.id</a>&quot;))</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">class EntryManager(rdb.Model):</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    rdb.metadata(metadata)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    rdb.tablename(&quot;entry_managers&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    id=Column(&quot;id&quot;, Integer, primary_key=True)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    myOtherStuff = Column(&quot;my_other_stuff&quot;, String(16))</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    containerA = relationship(&quot;Entry&quot;, secondary=&quot;entries_container&quot;, backref=&quot;backup_entries&quot;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    containerB = relationship(&quot;Entry&quot;, secondary=&quot;entries_container&quot;, backref=&quot;backup_entries&quot;)</span><br style="font-family: courier new,monospace;">

<br>but I am not capable of using containerA and containerB as a regular<br>list() object... Something is failing. When I try to set up the tables<br>it says:<br><br><i style="font-family: courier new,monospace;">ArgumentError: Could not determine join condition between parent/child<br>

tables on relationship EntryManager.containerA. Specify a<br>&#39;primaryjoin&#39; expression. If &#39;secondary&#39; is present, &#39;secondaryjoin&#39;<br>is needed as well.</i><br><br>Thank you very much<br>