Model Code
Explore how to implement bidirectional associations between JavaScript classes by coding setters, add and remove operations for linked properties, managing derived properties during storage, and handling deletion dependencies. This lesson helps you build coherent object interactions in your front-end models.
Code each class of the JS class model
For instance, the Publisher class from the JS class model is coded in the following way:
We add the derived multivalued reference property publishedBooks, but we don’t assign it in the constructor function. This is because it’s a read-only property that’s assigned implicitly when its inverse leader reference property Book::publisher is assigned.
Code the set methods of single-valued properties
Any setter for a reference property that’s coupled to a derived inverse reference property also needs to assign, add, or remove inverse references to and from the corresponding collection value of the inverse reference property. An example of such a setter is publisher in the Book class:
For any multivalued reference property that’s coupled to a ...