Problem/Motivation

Proper Views support for Non-Node-entities was added here: #2400211: Add Views support for non-node entity types
The Workflow Views give wrong results in the following case:
- Using Entity references:
1) Create content type A
2) Create content type B
3) Make content type B reference content type A
4) Create workflow used for content type A
5) Create view that select content type B, add relationship to content type A, add field current comment for content type A (with relationships)

- Using Node Revisions:
1) Create a view for 'Content revisions'
-> The Workflow Views give an error "Unknown column 'node.nid' in 'where clause'".

- Using Node Revisions:
1) Create some content with workflow_field
2) for a node, change status several times, add a revision, again change state a few times.
3) show the results in /workflow page (the 'dashboard').

- Using multiple Workflow Fields per entity type:
1) Create some content with workflow_field1 and workflow_field2;
2) create a view;
3) only the field with the latest transition is shown.

Proposed resolution

Change the table join in function workflow_views_views_data_alter() in file workflow_views/workflow_views.views.inc

Remaining tasks

The Patch in #16 is a good start. It will show data based on any entity type.
Patch #16 solves the second case, but still gives wrong results in the following casse:
Extend the path in #16 to work correctly with all Transition key fields: revision_id, field_name, language

Original report by VovkaTS

I had this problem "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'workflow_node.stamp' in 'on clause'" when i want to get Current comment.

Comments

VovkaTS’s picture

StatusFileSize
new5.18 KB
nancydru’s picture

Status: Fixed » Needs review

Correcting status

johnv’s picture

I cannot reproduce your error.
I installed Workflow and Workflow Views. Table 'workflow_node' contains the column 'stamp' as expected.
I created a Content View, added all 'Workflow...' fields. The View works a expected.
Is it because you want to use the 'fancy' field to field join from #1090432 ?

igor.ro’s picture

@johnv to reproduce follow this steps.

1) Create content type A
2) Create content type B
3) Make content type B reference content type A
4) Create workflow used for content type A
5) Create view that select content type B, add relationship to content type A, add field current comment for content type A (with relationships)

workflow_node works ok for base content type and does not work for content type with relationships, because that code does not use alias

johnv’s picture

Component: Workflow Views » Views

Reassigning.

johnv’s picture

Version: 7.x-1.x-dev » 7.x-1.2
Issue summary: View changes
Status: Needs review » Fixed
Parent issue: » #2147535: Add a "Last transition" views filter

For another issue, the following, apparently wrong join was removed in #2147535: Add a "Last transition" views filter :
'extra' => 'workflow_node.stamp = workflow_node_current.stamp AND workflow_node.nid = workflow_node_current.nid',

Your code contains more changes, but I trust the problem is gone with version 7.x-2.x

igor.ro’s picture

This code
'left_query' => " SELECT max(hid) FROM {workflow_node_history} where nid = node.nid and sid != old_sid ",
would not work either with views relationships.

johnv’s picture

Status: Fixed » Active

OK, open again, then.

johnv’s picture

Title: Unknown column 'workflow_node.stamp' in 'on clause' » Wrong data when using references.
Priority: Major » Normal

I'm testing this with Entity Reference to create the reference from A to B. (both having a Workflow Node.)
I do not get your error, but indeed: only the data from the main entity is shown. The reference entity B also shows the data from entity A.

The 'history comments' are fine.

johnv’s picture

Your patch contains a lot of code for xss, indicating it only solves the 'comment' part.

There is also an error with the other fields of a transition: 'current status', 'time', etc.
IMO the problem should be addressed using the correct table-joins, solving this for all fields.

igor.ro’s picture

only the data from the main entity is shown. The reference entity B also shows the data from entity A.

That is the problem. If you add node title field for A and for B, in views you expected to have different values, not the same for main entity.

I'll check patch again to exclude xss.

igor.ro’s picture

IMO the problem should be addressed using the correct table-joins, solving this for all fields.

If you will confirm that you will merge the same fixes for other fields, we will create patch for them also.

johnv’s picture

Yes, I am happy to correct all fields.
I think the problem is in the tables, not the subfields themselves.
P.S. I just made another commit #2149121: Restructure workflow_views_views_data(). on the same code. Please be sure to use the latest code.

johnv’s picture

Status: Active » Postponed (maintainer needs more info)
tucho’s picture

Version: 7.x-1.2 » 7.x-2.x-dev
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.46 KB

I wrote a work-around for the problem using "Workflow current" with views relationships, as described in #7.

It searches for the last state of every node using a "table formula" with subqueries, instead of using the views_join_subquery handler.

tucho’s picture

My patch from #2074859-15: Views displaying wrong data when using references/revisions/multiple fields have a bug when using more than a workflow field in a content type.

When grouping the rows from workflow_node_history to obtain the latest state of every node, my original query removes all workflow fields except the last one which has a state change.

Now I group by nid and field_name, so the query obtains the latest state from every workflow field of every node.

johnv’s picture

Title: Wrong data when using references. » Wrong data when using references in Views
VenDG’s picture

The patch in #16 fixes the "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'node.nid' in 'where clause'" error that was present in my views after updating to 7.x-2.x.

johnv’s picture

Issue summary: View changes
Status: Needs review » Needs work
Related issues: +#2400211: Add Views support for non-node entity types

Patch #6 seems like a step in the good direction. However, I get some wrong results (added in summary).
Also, the code base has changed ITMT.
Can someone take a look at #16 using latest dev-version?

johnv’s picture

Title: Wrong data when using references in Views » Wrong data in Views when using references/revisions/multiple fields
VenDG’s picture

I redid #16 against the stable version - 7.x-2.5. The error I was receiving is gone.

johnv’s picture

Issue summary: View changes

Thanks, @VenDG. We still need some db_query guru to solve the problems in the Issue Summary.

Mouna Hammami’s picture

Hello,
I was experimented the same problem when trying to get the workflow's new state of revisions.
For this reason, i have improved the patch #21 to support node_revision entities.
You can try this in this patch(D7 version). It works well for me
Have fun !

  • johnv committed 62ac5ab on 7.x-2.x authored by Mouna Hammami
    Issue #2074859 by tucho, VovkaTS, VenDG, Mouna Hammami: Wrong data in...
johnv’s picture

Thanks all! #23 was committed.
I leave this issue open, until I checked/tested all open problems/sub-issues in the Issue Summary.

johnv’s picture

Title: Wrong data in Views when using references/revisions/multiple fields » Views displaying wrong data when using references/revisions/multiple fields