4

I have a couple of custom entities defined by my module against plain tables in my database (because I have a lot of data and don't want to unpack it all into fields).

My contact entity has a entity_reference field to my subject entity with unlimited cardinality:

$fields['subjects'] = BaseFieldDefinition::create('entity_reference')
                    ->setLabel(t('Subjects'))
                    ->setSetting('target_type', 'pw_subject')
                    ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
                    ->setdisplayOptions('view', array(
                      'type' => 'entity_reference_entity_label'))
                    ->setDisplayOptions('form', array(
                      'type' => 'entity_reference_autocomplete'));

The subject entity is very simple with just id and name fields.

This causes the Entity API to create a join table and it all seems to work with regular node viewing and editing. However when I try to add a relationship in view a view based on contact to subjects I get an SQL error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pw_contact__subjects.subjects' in 'on clause': SELECT pw_contact.id AS id, pw_subject_pw_contact__subjects.id AS pw_subject_pw_contact__subjects_id FROM {pw_contact} pw_contact LEFT JOIN {pw_contact__subjects} pw_contact__subjects ON pw_contact.id = pw_contact__subjects.entity_id AND pw_contact__subjects.deleted = :views_join_condition_0 LEFT JOIN {pw_subject} pw_subject_pw_contact__subjects ON pw_contact__subjects.subjects = pw_subject_pw_contact__subjects.id LIMIT 11 OFFSET 0; Array ( [:views_join_condition_0] => 0 )

It looks seems views is looking for a subjects column rather than the subjects_target_id that it should use - it seems to think this is a value field rather than a reference?

Anyway I'm a bit lost in the code trying to work out what's going on so any pointers appreciated.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.