2

I have an entity that uses two tables, when I describe it in hook_entity_info() as far as I know I can only tell it about the base table. The base table is subscriber, I also have a table disease_catagories which stores the results of a select list. (stores the subscriber id, and the taxonomy term id. It can store any number of items with the same subscriber id and different taxonomy term ids)

I need the entity to contain an array of those taxonomy term ids, but I don't know how to connect that database table with the base table. are there any good articles that discuss how to attach a second table to the entity (maybe as field data)?

5
  • 2
    Entity API only knows how to work with one. Other related data would be considered field data I think
    – Clive
    Aug 11, 2015 at 20:54
  • 1
    Do you know of any good articles about how to work with field data in this case?
    – Eluchel
    Aug 11, 2015 at 20:59
  • 'Fraid not. Maybe you could edit the question and add some more specific details about the architecture/what's in the tables etc. Might make it easier to understand what you're looking for and how core/contrib can help
    – Clive
    Aug 11, 2015 at 21:27
  • You should be able to tack on anything you like as property data but you'll be responsible for that in your load function.
    – Aaron
    Aug 12, 2015 at 0:44
  • Do you know of any good articles/documentation/videos that explain how to do that? I have been looking, but so far everything has either been way too complicated or not addressed the issue.
    – Eluchel
    Aug 12, 2015 at 1:03

1 Answer 1

0

Entity API itself can only interact with one base table for joining to fields, querying with EntityFieldQuery, loading/saving revisions, etc, but you can use more than one table for storage if you implement your own storage controller which you can specify in your hook_entity_info().

You'll want to subclass DrupalDefaultEntityController and override the load() method and buildQuery() method if you want some EntityFieldQUery support.

If you are using Entity API module, you'll want to extend EntityAPIController and override the save(), load(), and delete() methods for full CRUD support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.