2

I have the following query shown in one of my views:

SELECT node.nid AS nid, node.title AS node_title, node.created AS node_created, 
node.sticky AS node_sticky, 
'node' AS field_data_field_featured_image_node_entity_type, 
'node' AS field_data_body_node_entity_type, 
'node' AS field_data_field_premium_content_node_entity_type, 
'node' AS field_data_field_article_type_node_entity_type, 
'node' AS field_data_field_video_upload_node_entity_type
    FROM 
    {node} node
    INNER JOIN {field_data_field_sports_type} field_data_field_sports_type ON node.nid = field_data_field_sports_type.entity_id AND (field_data_field_sports_type.entity_type = 'node' AND field_data_field_sports_type.deleted = '0')
    WHERE (( (node.status = '1') AND (node.type IN  ('article')) AND (field_data_field_sports_type.field_sports_type_tid = '1884') ))
    ORDER BY node_sticky DESC, node_created DESC
    LIMIT 8 OFFSET 1

What does the 'node' in this query return, for instance when I'm calling:

...'node' AS field_data_field_featured_image_node_entity_type,

It seems to me that this should just return the string "node" but in the preview it's actually showing the image. When I do the SQL query in the console it's just returning the string 'node'. I'm confused because I don't see any JOIN statements on things like the field_featured_image table in this query, which I would have expected if the query actually was pulling the image.

How is the image getting shown via this query?

1 Answer 1

0

It's utilizing a loaded entity to fill in these placeholder columns. Per the views_handler_field_field::query() docs:

By default, the only columns added to the query are entity_id and entity_type. This is because other needed data is fetched by entity_load(). Other columns are added only if they are used in groupings, or if 'add fields to query' is specifically set to TRUE in the field definition.

In the post-execute phase, during views_handler_field_field::post_execute(), you can see where the field values are dropped in from the entity values.

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.