How to define custom content entity one to many relationship? I have two custom entities; A, B.

In terms of database relationships, I want A to have many B.

I find I am able to define a reference_entity field in the entity's baseFieldDefinition(). However, because this just defines a single column in the database my relationships are back to front:

I can give B a reference to A and then use $B-&gt;getEntity()-&gt;referencedEntities() to get a B's associated A, but I can't do it the other way round because there's just a single id for each row.

Is there a correct way to query or set up these kinds of relationships 'out-the-box' or is a better solution to add my own method to the A entity getReferencedBs() and query the B table for references to A.

Many thanks
Sounds like you need to add setCardinality(-1) to your B reference field definition in your A entity. This will change the B reference field to support an unlimited number of references instead of 1, the default cardinality.