Model development choice
<p>Lets say, that I'm want to develop a game (RTS-like, with economy orientation) in which player, as well as AI, can posses almost every in-game object. For example: player posses a land and some buildings on it; other players, or AI can also have some buildings, or else, on this land piece; also, someone can posses an entire region with such land pieces and sell some of it to others. Possesable objects can be movable, or immovable, but all of them have common attributes, such as owner, title, world coords and so on. What DB structure with respect to Django models will be most suitable for this description? </p>

<ul>
<li>Owner_Table - (one-to-many) - PossesableObject_Table</li>
<li>PossesableObject_Table - (many-to-many) - PossesableObject_Table (in 
example, building linked to land piece where it is)</li>
</ul>

<p>or</p>

<ul>
<li>Owner_Table - (one-to-many) - PossesableObjectType_Table (table for each type of possible object)</li>
<li>PossesableObjectType_Table - (one-to-many) -<br>
PossesableObjectType_Table (for already explained above type of<br>
linking)</li>
</ul>

<p>The questions you should ask are the following:</p>

<ol>
<li><strong>Can</strong> A be linked to at most 1 or many (more than 1) B?</li>
<li><strong>Can</strong> B be linked to at most 1 or many A?</li>
</ol>

<p>If A can be linked to many B and B can be linked to many A, you need a many-to-many link.</p>

<p>If A can be linked to at most 1 B and B can be linked to many A, you need a one-to-many link, where the link column is in table A.</p>

<p>If A can linked to at most 1 B and B can be linked to at most 1 A, you need a one-to-one link. At this point you should consider whether is viable to join them into 1 single table, though this may not be possible or good from other considerations.</p>

<p>In your case, you ask yourself the question: Can a PossessableObject be linked to only at most 1 other PossessableObject or many other PossessableObject? Or in other words: Can a PossessableObject be owned by only at most 1 other PossessableObject or many other PossessableObject? If the answer is at most 1, use a one-to-many link, if the answer is many, use a many to many link. </p>

<p>Also with regard to your question on a PossesableObject_Table for each possible type of object: I think it is best to put the things they have in common in a single table and then specify types. Than create a seperate table for each type of object that has the unique properties of an object and connect those, but your way will work as well. It depends on how many different types you have and what <strong>you</strong> find the easiest to work with. Remember: as long as is works it is fine.</p>

python django-models