Media
entity, which is used to catalog and organize all media items loaded in to my application.Media
entity contains all of the properties which are common to every media item uploaded in to my application. Let's say, however, that I need to have specific attributes that are available on only media for my Book
entity ( e.g. whether the image is the cover photo, for example ). I can create a child class of BookMedia
which extends my Media
entity. When loaded, all of the properties of Media
will be loaded along with the custom attributes which apply to my BookMedia
object:joincolumn
. The presence of this attribute on a child class signifies that it is a child entity of the parent and that the parent's properties should be loaded whenever the BookMedia
entity is loaded. In addition, the primary key of the entity is that of the parent.table
attribute is required on a child entity if the parent entity has one. This is because ColdBox will perform a deep merge on the entire inheritance chain for metadata properties. If a parent class has a table
attribute, it will show up as the child's table
attribute.joinColumn
, which should be a foreign key to the parent identifier column:Book
entity can use its extended media class to retrieve media items which are specific to its own purpose:discriminatorValue
attribute and will return that specific class when a retrieval is performed through the parent Entity. Let's take our BookMedia
class, again, but this time defining it as a discriminated entity.discriminatorColumn
attribute to the Media
entity:discriminatorValue
property on the child class, the value of which is stored in the parent entity table:BookMedia
entity will be saved with a type
value of book
in the media
table. As such, the following query will result in only entities of BookMedia
being returned:Media
table contains a combination of non-book and book media, then the collection returned when querying all records will contain a mix of BookMedia
and Media
entities.BookMedia
entities, however, will always return a collection of BookMedia
entities, because the type
column value on the media
must be equal to book
.