Assigning a model to several other models in one relationship

I have a model Thingthat can be subclassed by several types Thing, such as PointyThingand TastyThing. I have a second model, Instancewhich is tied from one to many to Thing(one Instancemay be of the type of one Thing, but there will be a lot of Instancethis Thing). Instancethen associated with a Player(each Instancehas one Player, but a Playerhas many Instances) with backref, so a Playercan call it a property to .inventorysee what it owns.

All is well and good, but I also have a model Place. I would like to Placeown, Instancetoo, in the same way that a Playerowns Instance.

Would it be better to create a model Ownerthat is associated with the model Instanceand then subclassed to get Playerand Placeor some unknown method in SQLAlchemy that I don't know yet from?

+3
source share
1 answer

I think that the decision bestyou request depends on many factors.

, , hack, relationship. , . . , Player , , "how will it impact my hack"?. ( , ), .
, ? relationship, Owner ( ), ?

, , Instance ternary? , Thing Place Player, , :

Instance[
    ID primary_key, 
    Thing_ID (FK) NOT NULL, 
    Place_ID (FK) NOT NULL, 
    Person_ID (FK) NULL
]

, Person_ID NULL, , Thing - . , NOT NULL .

, . , .

+2

All Articles