I'm attempting to create a view that shows just the distinct manufacturers for a list of products.

The raw product list is below: Manufacturer and Product Type are taxonomy terms.
Product 1 (Manufacturer A/Product Type 1)
Product 2 (Manufacturer A/Product Type 1)
Product 3 (Manufacturer B/Product Type 1)

I want the results to be:
"Manufacturer A"
"Manufacturer B"

Steps to reproduce:
1. Create two vocabularies, "Manufacturer" and "Product Type."
2. Add the two taxonomy fields to a Product content type.
3. Create three products and assign the taxonomy terms according to the list above.
4. Using the "Taxonomy Term" template view, switch the Format type to "Fields" from "Content.
5. Add the Manufacturer taxonomy field ("Content: Manufacturer") to the field list to display only that field.
6. In the preview, provide a product type taxonomy term and it should show all three products fine.
7. Turn Aggregation on.
8. The auto preview will immediately return:

EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7389 of /Users/aangel/LocalDevelopment/htdocs/drupal-7.8/includes/common.inc).
9. Replace the only displayed field "Manufacturer Term" with the Title and the three products again show up fine.

This particular template view appears to have trouble aggregating on a taxonomy term. The problem may exist in other view types and if I find that to be the case as I look for a workaround I'll report back.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Groupby is probably not what you actually want.

You have to know that you can either have a field groupby by OR in the COUNT/SUM/MAXIMUM part not just displaying one single per GROUP.

But there is something in views for this, but it was later added then the RC so you might have to update to the dev version.
Therefore please read /views/help/relationship-representative.html which explains this a bit better.

aem34’s picture

hello,

i did this by doing like this :

- format: table
parameters :
under the table for the fields,
there's a "grouping field" popup menu.
please choose here your taxonomy term field which is already appearing on choosen fields of your view.

then on your view page/attachment/etc you'll see
(name of the view)
(taxonomy term, manufacturer A or something else)
(table regrouping all lines corresponding to your manufacturer A)

(taxonomy term, manufacturer B or something else)
(table regrouping all lines corresponding to your manufacturer B)

and so on

aangel’s picture

Status: Active » Postponed

I'm having trouble parsing this statement:
"You have to know that you can either have a field groupby by OR in the COUNT/SUM/MAXIMUM part not just displaying one single per GROUP."

but I got the part about trying the dev version. I used a custom query in the meantime. I'll reopen the issue if I go back to trying this method.

stella’s picture

Status: Postponed » Active

I'm having a similar problem, and I'm afraid I also can't understand the meaning of your response dereine.

I'm using a view of type "quiz" (rather than "node") but am pulling in the nodes via relationships - just in case that matters.

In my view I'm displaying a list of question nodes, the taxonomy term for each, and the score the user achieved for that question. However, I want to change this to an aggregate view where I display the taxonomy term and the average (or sum, i don't mind!) of the scores for all questions tagged with that term. Once I do that though, I get the error as above:

EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7389 of /Users/stella/d7/glen.localhost/includes/common.inc).

I'm happy to work on this and debug it some more, but I'm unsure from your comment whether it's my configuration that's wrong or something in views. I just need some pointers on where to go from here.

I'm using views 7.x-3.0-rc1 and Drupal 7.8

stella’s picture

Ok just to be sure it wasn't the quiz module interfering (and to ensure I knew how aggregation worked with a simple example), I created another view containing the node type and nid. I set the aggregation setting for the nid to be "count" and the node type to be "group results by". This all worked fine - once I removed the "order by post date" as that was added to the group by too.

Next I removed the "node type" field and added in the taxonomy term that each of the nodes were tagged with and set the aggregation setting to be "group results by" for this. It gave me the same error as above. I don't see how this can be my views configuration settings now.

stella’s picture

FileSize
6.34 KB

Views export attached. I can't make any further edits to it now as I just get the error screen and message :(

If I added in debug() messages to common.inc where that error is spewed out, I can see that $info contains node related information with $info->['entity keys']['bundle'] set to "type". However, a debug of $entity gives the following:

array (
  0 => 
  array (
    'tid' => '1',
  ),
)

I'm happy to debug it further but am a bit stuck.

stella’s picture

I figured out a solution for this. Basically if you add in a relationship on the taxonomy term field and then display the "taxonomy: term name" field rather than the term reference field on the node, aggregation then works.

rafboh’s picture

I have the following issue:
1. Drupal 7.8, Views 7.x-3.0-rc1
2. I created a simple content type containing integer field
3. Defined a view with two fields: above mentioned integer field and content NiD. Works fine.
4. Switched on aggregation with the following aggregation settings: Count for integer field and AVG for Content:Nid, works fine. SQL query attached below

SELECT COUNT(field_data_field_apples.field_apples_value) AS field_data_field_apples_field_apples_value, COUNT(field_data_field_apples.delta) AS field_data_field_apples_delta, COUNT(field_data_field_apples.language) AS field_data_field_apples_language, COUNT(field_data_field_apples.bundle) AS field_data_field_apples_bundle, AVG(node.nid) AS nid
FROM
{node} node
LEFT JOIN {field_data_field_apples} field_data_field_apples ON node.nid = field_data_field_apples.entity_id AND (field_data_field_apples.entity_type = 'node' AND field_data_field_apples.deleted = '0')
WHERE (( (node.status = '1') AND (node.type IN ('pr_ba_agregacji')) ))
LIMIT 10 OFFSET 0

5. Change aggregation settings for integer field from COUNT into SUM. I get the following error : EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7389 of ......

Same problem for Average, Max and Min. Only COUNT works. For Content:Nid field all functions are working fine. I cannot find any solution for this problem.

zhgenti’s picture

Hello,

I've encountered same troubles with aggregation.
It happens because of collisions with variables names in the get_value() function of views_handler_field_field.inc file.
Here is patch which fixes this.

Thanks,
Dmitry

zhgenti’s picture

Status: Active » Needs review
dawehner’s picture

Status: Needs review » Fixed

It seems to be that exactly this change is already fixed in the current dev version.
Thanks for providing a patch anyway. Next time better checkout out the dev version as there is always fixed a LOT of things.

Status: Fixed » Closed (fixed)

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

joachim’s picture

Version: 7.x-3.0-rc1 » 7.x-3.1
Status: Closed (fixed) » Active

Not sure if this is related, but on 3.1 I'm getting:

Fatal error: Cannot access empty property in modules/field/field.attach.inc on line 324

This is caused by an aggregated view with a taxonomy term ref field, where the term ref field does not exist on all the entities that are returned in the results.

David_Rothstein’s picture

Version: 7.x-3.1 » 7.x-3.0-rc1
Status: Active » Closed (fixed)

I can reproduce that same problem, but it's not just limited to taxonomy term reference fields - it occurs with other fields too.

I filed a new issue for it at #1461536: Fatal error when using aggregation and a field is not attached to all entities in the view; probably better to deal with it there, so I'm setting this issue back to its previous status.

kenorb’s picture

Issue summary: View changes

fixed some typos