Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I've created two custom entities and need to create a one to many reference between them. What I would like to achieve is to have the Child entity with field Parent that would reference the Parent entity. On the other hand, the Parent entity should have field with collection of Children entities.

The Entity reference module seems like the obvious choice, but how do I use it strictly from code to reference my custom entities in the way I described?

I also thought of just using Entity's API Entity::setUp() to load the references. This solutions seems simpler but what is the best Drupalish approach?

Both entities are fieldable.

share|improve this question
 
Hello and welcome. Asking about "the correct way" is edgy - it can get easily closed as primarily opinion based. Now, other than that your needs are pretty clear. If you could add what have you tried? and is your entity fieldable? Can it be fieldable? –  Mołot Oct 24 at 12:32
 
@Mołot I've changed the title :). Both entities are fieldable. I'm currently experimenting with Entity::setUp(), but this is very early stage of development. I'm looking for advice before I go further and make bad design decisions. –  SiliconMind Oct 24 at 13:05
 
If your entities are fieldable, the simplest way would be to use Entity reference module on them, by binding field's instance to bundles. Unfortunately I can't take enough time to actually write samples now. –  Mołot Oct 24 at 13:14
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.