Mike Orr wrote:
> Chemical:
>     canonical_name = ForeignKey("Name")
>     names = RelatedJoin("Name")
>
> Name:
>     name = StringCol(notNone=True)
>     chemicals = RelatedJoin("Chemical")

> The other annoyance is chemical.canonical_name and chemical.names are
> records rather than just the string names, so I have to dereference
> them again: chemical.canonical_name.name .  But the Name table has
> only one "interesting" field, and the same for five other M:M
> relations I have.  I guess I could rename the attributes and use
> properties to make .canonical_name and .names look like strings, but
> propagating changes to .names back to the database would be
> complicated.

SQLObject makes doing this less of a pain than it sounds.

class Chemical(SQLObject):
  canonical_record = ForeignKey("Name")

  def _get_canonical_name(self):
    return self.canonical_record.name

  def _set_canonical_name(self, value):
    self.canonical_record.name = value

...

Reply via email to