On 1/28/20 9:03 AM, 'Radoslaw Krzak' via sqlalchemy wrote:
> Hey Simon,
>
> *address_id* is *not* a primary key and is not unique across the
> *addresses* table. *One* /Company/ can reference *many* addresses rows
> (because there might be multiple rows with the same
> *address_id* value, hmm maybe I should have used a different name) and
> vice-versa, *one* /Address/ can be referenced by *many* companies, so
> it's many to many. The point is I am not linking by primary keys, but
> simply by the value of *address_id* column. This is a deliberate
> action and I would love to see how I could set up such a relationship
> using *primaryjoin, foreign_keys *and***remote_side (if necessary)* :)
>
> Radek
>
> On Tuesday, January 28, 2020 at 9:28:06 AM UTC, Simon King wrote:
>
> Company has an address_id column, which means each company only has a
> single address, doesn't it? ie. this is a many-to-one relationship,
> not a many-to-many?
>
I suspect this design has some unintended consequence that you might not
have thought about. If a company that has multiple locations shares one
of its locations with another company, but not all of them, either you
need to incorrectly imply that the second company is at all the first
companies locations (give them the same address-id) or imply that they
don't share that location (give them different address-id). This latter
case requires that you might need to create multiple records for the
exact same place (with different address-ids) which would be a violation
of the normal form, and makes operations for creating these
relationships very complicated.
--
Richard Damon THis