Working on Og I've noticed For example EntityReference_SelectionHandler_Generic_node::entityFieldQueryAlter expects the node table

$tables = $query->getTables();
$query->condition(key($tables) . '.status', NODE_PUBLISHED);

But the tables don't get the node table -- just the field's table. Will need to investigate more...

Comments

dpi’s picture

It seems #1359212: EntityReference_SelectionHandler_Generic_node::entityFieldQueryAlter() expects the base table to be there has been marked as a duplicate of this issue.

I'm getting PDOException's when changing 'A field attached to this entity' to any value. The field works fine when running as a user with admin role.

rsgracey’s picture

In addition to getting the PDO errors, the drop-down select for the fields never saves: It's always the field at the top of the list, which in my case, is always "Body (Value)," regardless of whether I'm logged in as admin or not.

ohthehugemanatee’s picture

Noting that this error exists for me as well. I'd say it's a simple join missing from the query, but it works as admin...

anyway, this completely breaks the ability to sort by anything other than the base table.

xenophyle’s picture

If anyone needs an alternate way of sorting the entity reference nodes, here is a brief description of how I did it using Views. In my example I had a Product node that had an entity reference field that referenced nodes of type Feature.

1. First I created a view with a block display that filters on the Feature content type.

2. Then I added a relationship "Entity Reference: Referencing entity". (This basically means the Feature table is being joined to the Product table.)

3. Then I added a contextual filter "Content: Nid", and I chose from the Relationship dropdown "Content referencing Content from field_features". In your case "field_features" may be something different.
3a. Under "When the filter value is NOT available" I chose "Provide default value" and "Content ID from URL". This means that when viewing a Product page, the view will find the Product's nid in the url and it will show only Features that are referenced by that Product.

4. After saving the view, I went to the block admin page and set the block to display on the desired pages and the desired region.

amitaibu’s picture

Status: Active » Needs review
StatusFileSize
new4.48 KB

How about this approach (not tested thoroughly yet)

antonyanimator’s picture

I get the following error when trying to change an entity reference field on a node with an authenticated user.

It works fine as super user, so I thought it was a permissions issue. However with all permissions turned on for the relation module I still get the error.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'nid' in where clause is ambiguous: SELECT DISTINCT node.nid AS entity_id, node.vid AS revision_id, node.type AS bundle, :entity_type AS entity_type FROM {node} node INNER JOIN {node_access} na ON na.nid = node.nid WHERE (nid IN (:db_condition_placeholder_0)) AND (type IN (:db_condition_placeholder_1)) AND(( (na.gid = :db_condition_placeholder_2) AND (na.realm = :db_condition_placeholder_3) )OR( (na.gid = :db_condition_placeholder_4) AND (na.realm = :db_condition_placeholder_5) )OR( (na.gid = :db_condition_placeholder_6) AND (na.realm = :db_condition_placeholder_7) ))AND (na.grant_view >= :db_condition_placeholder_8) ; Array ( [:db_condition_placeholder_0] => 18 [:db_condition_placeholder_1] => products_services [:db_condition_placeholder_2] => 0 [:db_condition_placeholder_3] => all [:db_condition_placeholder_4] => 11 [:db_condition_placeholder_5] => content_access_author [:db_condition_placeholder_6] => 2 [:db_condition_placeholder_7] => content_access_rid [:db_condition_placeholder_8] => 1 [:entity_type] => node ) in EntityFieldQuery->execute() (line 1136 of /home/e-smith/files/ibays/hglass1/html/includes/entity.inc).

amitaibu’s picture

@antonyanimator, is this error after applying the patch in #5?

rainman-2’s picture

@Amitaibu The patch worked for me! Awesome job.

That's the first patch I've every applied. For future first time patchers, you'll have to follow this guide to clone the entityreference project.

How do we go about submitting this patch so that is can be released in the next version of entity reference? I feel like this functionality is a big deal!

Thanks again, @Amitaibu.

rainman-2’s picture

Status: Needs review » Reviewed & tested by the community

I'm marking this as "reviewed and tested by the community" so we can get this in the next update.

amitaibu’s picture

Status: Reviewed & tested by the community » Needs review

Correct status

damien tournoud’s picture

Priority: Normal » Critical

Marking as a release blocker.

amitaibu’s picture

Issue tags: +Release blocker

Adding tags.

Taxoman’s picture

Marked #1567304: File Entity clash (I think) as a duplicate of this issue.

twardnw’s picture

Using the scenario in #1359212: EntityReference_SelectionHandler_Generic_node::entityFieldQueryAlter() expects the base table to be there I was able to reproduce this.

The patch in #5 applied clean and resolved the error for me.

malberts’s picture

Patch #5 works for me with entityreference-7.x-1.x-dev (2012-Oct-29).

My scenario: I'm using Commerce with an Entity reference field on the line item form (on the Add to Cart form). My field references nodes and sorts by the title field (not the title property, I replaced it via the title module). I got an error similar to #1359212: EntityReference_SelectionHandler_Generic_node::entityFieldQueryAlter() expects the base table to be there when logged out. The patch solves this issue for me.

senpai’s picture

Status: Needs review » Reviewed & tested by the community

Sounds like comments #14 and #15 make this an RTBC issue. Let's get this patch applied and roll a stable release, shall we?

amitaibu’s picture

Indeed, that's the last release blocker.
@Damz, are you ok with this patch, and rolling a first stable?

amitaibu’s picture

Status: Reviewed & tested by the community » Needs work

Current patch in #5 simply skips over the access. We need to try and extract the base table from the query.

amitaibu’s picture

Issue summary: View changes

The patch in comment #5 is RTBC.

amitaibu’s picture

Assigned: Unassigned » amitaibu

I'm working on this.

amitaibu’s picture

Status: Needs work » Needs review
StatusFileSize
new3.57 KB

Let's see if tests pass.

amitaibu’s picture

StatusFileSize
new3.31 KB

Removed iterating over conditions, and just add the base-table.

amitaibu’s picture

StatusFileSize
new6.83 KB

Added test.

amitaibu’s picture

StatusFileSize
new6.84 KB

Better use assertIdentical() to check the sort order..

amitaibu’s picture

Status: Needs review » Fixed

Committed.

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.