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

--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/569fdc31-883c-9c20-24fe-5f43223af522%40Damon-Family.org.

Reply via email to