Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It seems that you are running into the famous <a href="http://en.wikipedia.org/wiki/List_of_object-relational_mapping_software" rel="nofollow">Object Relational impedance mismatch</a></p> <p>There are many approaches and it depends on various factors. For example the size of the object graph you are loading, number of relations, type of persistence storage. It can get complex quickly.</p> <p>My suggestions are:</p> <ul> <li>Do not mix persistence code with your business logic code. Those are separate concerns.</li> <li>Make use of an id/foreign key field to define the relationship (as you were leaning towards).</li> <li>Introduce a factory or more specific a <a href="http://en.wikipedia.org/wiki/Builder_pattern" rel="nofollow"><strong>Builder</strong></a> that will act on the load side of an <a href="http://martinfowler.com/eaaCatalog/dataMapper.html" rel="nofollow">Mapper</a>. Builders normally are uses for "complex cases", but you can get away with a Factory class too.</li> <li>The Builder will make use of you loader class (looks like ClassBFactory to me) to construct ClassB.</li> <li>The Builder will then need to get/have a reference to ClassB and then set it on ClassA if needed.</li> </ul> <p>Some theoretical background:</p> <p>Persisting objects can get complex and there are many "holes to fall in". Consider using a pre-build <a href="http://en.wikipedia.org/wiki/List_of_object-relational_mapping_software" rel="nofollow">ORM mapper tool</a>.</p> <p>But you can get away if you only have <em>simple</em> ORM use cases. Take a look at the <strong>Object-Relational Structural Patterns</strong> and <strong>Object-Relational Metadata Mapping Patterns</strong> by <em>"Master Fowler"</em> <a href="http://martinfowler.com/eaaCatalog/index.html" rel="nofollow">here</a>. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload