While implementing views into a contrib module that I was working on I had to join multiple base tables on more than one field-to-field condition. I noticed that the default views_join handler doesn't provide that functionality. Only the first condition defined by "field" and "left_field" provides a field-to-field join. The 'extra' assignment however only allows field-to-value conditions. Daniel and me were wondering if this could be achieved by adding an additional array element (left_field) to 'extra'.

Here is the code that we came up with: http://pastebin.com/ZL2CxFVF

I tested it with my module and it seems to work. This is an example for the required array structure: http://pastebin.com/T6rsicCQ

Comments

dawehner’s picture

Can you please create a real patch? This would really help to bring this issue further.

I'm wondering whether this feature might be helpful on 6.x-3.x, too.

fubhy’s picture

Here is the patch for 7.x-3.x

merlinofchaos’s picture

Ok, this looks reasonable to me. CanI get one for 6.x-3.x too?

fubhy’s picture

Done for 6.x-3.x. Couldn't test it yet but the code is the same as for 7.x-3.x.

dawehner’s picture

Status: Needs review » Needs work

I'm sorry but the patch doesn't apply anymore against 7.x-3.x

fubhy’s picture

I will fix that later tonight! Thanks for the heads-up

dawehner’s picture

Man what a long night :)

Subscribe to this issue because i would like to have this issue in

fubhy’s picture

Whoops... Same with the other Issue :P. Fixing it NOW!

fubhy’s picture

Status: Needs work » Needs review
StatusFileSize
new4.2 KB

The build_join method has changed slightly since we worked on this the last time therefore I am not 100% sure if this still works as expected. I would be thankful for a review!

fubhy’s picture

The build_join method has changed slightly since we worked on this the last time therefore I am not 100% sure if this still works as expected. I would be thankful for a review!

derhasi’s picture

For #1451714: Extend content flag relationship with specific user relation I had a similar use case, and for the moment had to resolve that by using extra as a string and not an array.

fubhy, I reapplied your patch and extended it with left_table (it might be needed sometimes).
Additionally I added a formula info, so more complex on clauses could be managed.

Examples:

array(
  'field' => 'name',
  'formula' => 'LOWER(mytable.name)',
),
array(
  'formula' => 'TRIM(%alias.name) = TRIM(mytable.name)',
),

fubhy, dereine, do you think this will be a useful addition.

Sure, additional documentation was needed for the new functionality.

dawehner’s picture

Views in drupal6 has

 *   - - raw: If you specify raw the value will be used as it is, so you can have field to field conditions.

as a special flag in the extra array. It would be cool if there could be some kind of consistency here. Sorry for not remembering that, though this was added in hurry.

tim.plunkett’s picture

Triggering the testbot.

rudiedirkx’s picture

Status: Needs review » Reviewed & tested by the community

Oeh I really, really want this. I tried to do this 14 different ways without this patch and nothing worked. There's no way to pass a formula/expression to the query builder?

additional-field-to-field-conditions-1090432-11.patch works perfectly, both the 'left_field' + 'left_table' and 'formula' approaches.

johnv’s picture

@derhasi , your patch #11 contains 2 files. Which is the one to apply?

rudiedirkx’s picture

@johnv additional-field-to-field-conditions-1090432-11.patch worked for me. (The first, big one.)

If it's a simple join, use can use left_field and left_table. Otherwise, use formula.

The last submitted patch, 11: additional-field-to-field-conditions-1090432-11_w.patch, failed testing.

rudiedirkx’s picture

it-cru’s picture

Refactor patch from #11 against current code repo. Works for me with 7.x-3.8.

robertwb’s picture

Patch in #11 applies correctly and functions correctly in most recent git dev as of 2015/03/18.

colan’s picture

We've recently switched our testing from the old qa.drupal.org to DrupalCI. Because of a bug in the new system, #2623840: Views (D7) patches not being tested, older patches must be re-uploaded. On re-uploading the patch, please set the status to "Needs Review" so that the test bot will add it to its queue.

If all tests pass, change the Status back to "Reviewed & tested by the community". We'll most likely commit the patch immediately without having to go through another round of peer review.

We apologize for the trouble, and appreciate your patience.

rudiedirkx’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new5.01 KB
rudiedirkx’s picture

Status: Needs review » Reviewed & tested by the community

  • colan committed 09adda6 on 7.x-3.x authored by fubhy
    Issue #1090432 by fubhy, derhasi, rudiedirkx, IT-Cru: Allow additional...
colan’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 7.x-3.x-dev » 8.1.x-dev
Component: Views Data » views.module
Status: Reviewed & tested by the community » Patch (to be ported)

Thanks.

robertwb’s picture

Hey @colan - there is a bug in this patch when using an "IN" operator with only 1 value. NOt sure how to exactly proceed other than to note that the port to D8 should take note of this. I just posted an issue and patch (related: "Extra join conditions fails with 1 value using IN condition (2656852)". It involves adding a single line of code (patch snippet below).

@@ -1599,6 +1599,7 @@ class views_join {
                 $operator = $info['operator'] == 'NOT IN' ? '!=' : '=';
               }
               $info['value'] = array_shift($info['value']);
+              $info['operator'] = $operator;
             }

             if (is_array($info['value'])) {

robertwb’s picture

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

maximpodorov’s picture

I have the problem mentioned in #26 also (with NOT IN filter).

maximpodorov’s picture

Version: 8.2.x-dev » 7.x-dev
Category: Feature request » Bug report
Priority: Normal » Critical
Status: Patch (to be ported) » Needs review
StatusFileSize
new5.01 KB

The commit breaks existing sites with NOT IN filters. I suggest to revert it and find a non-destructive solution.

Status: Needs review » Needs work

dawehner’s picture

@maximpodorov I agree with you. Do you mind moving the issue back to views itself?

maximpodorov’s picture

Project: Drupal core » Views (for Drupal 7)
Version: 7.x-dev » 7.x-3.x-dev
Component: views.module » Code
Status: Needs work » Needs review
maximpodorov’s picture

So the reverting patch is OK now.

gedur’s picture

There is a backport of the D8 version of views for supporting left_tables #2642100: views_join doesn't allow extra conditions on left table but this patch does not apply now because of this issue.
Because of last comment I don't know if this commit will be reverted or not, so I need to roll the patch or wait. thanks!

hass’s picture

This introduced a regression that breaks all JOINs. Please create a new STABLE views release asap.

sam152’s picture

After upgrading from 7.x-3.11 to 7.x-3.14, I bisected views down to this issue that was breaking my filters. In my case I have a field being used in a AND/OR condition group, with the field existing on one bundle but not the other. Reverting this patch fixes my filters.

Will post further details of the bug if I come across it.

sam152’s picture

Attached is a revert patch.

Status: Needs review » Needs work

The last submitted patch, 39: 1090432-REVERT-22-modified-views-join-handler-39.patch, failed testing.

joelpittet’s picture

@Sam152 I think you just need the --relative flag on git when you created that patch from in the views folder in your project.

sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new5.01 KB

Hand-fiddled patch.

rudiedirkx’s picture

Reverting something that's already released... Is that a thing? I don't know what the issue is exactly, but the solution is being worked on in #2656852: Extra join conditions fails with 1 value using IN condition I think..

hass’s picture

If a patch only causes issues we typically revert it.

sam152’s picture

A fairly large and complicated patch committed with no tests? Two bugs caused by this change have been raised, are those are the only ones out there?

jromine’s picture

This introduced a regression that breaks extra with zero value #2791353: JOIN 'extra' fails with zero value

othermachines’s picture

Another problem report that looks to be related: #2754667: "In none of" (= Off/0) filter operator stopped working after Views update to 7.x-3.14 .

Wondering if any action is planned on this? I manually patched the security vulnerability in June and have since been holding out for 3.15.

jcnventura’s picture

Status: Needs review » Reviewed & tested by the community

Reverting this patch also fixed a problem introduced by 3.14.. Please commit the revert, until a test+fix can be committed again.

hass’s picture

For about 7 months a broken views release is shown on project home. Are the maintainers alive?

othermachines’s picture

Here's another re-roll of the reverting patch against today's security update (7.x-3.15).

A related fix for #2754667: "In none of" (= Off/0) filter operator stopped working after Views update to 7.x-3.14 was included in the release (commit) but I'm not feeling 100% confident it fixes all problems.

  • dawehner committed b5a14ea on 7.x-3.x authored by othermachines
    Issue #1090432 by fubhy, Sam152, derhasi, rudiedirkx, othermachines, IT-...
dawehner’s picture

Status: Reviewed & tested by the community » Needs work

I pushed the revert patch now. Thank you, well let's see whether someone is willing to work on the issue itself.

othermachines’s picture

Thanks a lot, @dawehner. Does it make sense to start by recreating the originally committed patch (for 7.x) with change in 63e1d67c7 and mark it "needs tests"?

jcnventura’s picture

@othermachines, it would. Make an interdiff between the new patch and the patch in #22. However, keep it at "Needs work", as this breaks a lot more than just the "none of" fixed in #2754667: "In none of" (= Off/0) filter operator stopped working after Views update to 7.x-3.14 . It breaks also NOT IN filters (#26, #27, #29 and #30) and apparently also field being used in a AND/OR condition group (#38].

jcnventura’s picture

Issue tags: +Needs tests
othermachines’s picture

Priority: Critical » Normal
StatusFileSize
new5.04 KB

Sorry, I lost track of this. Here is a re-roll of originally committed patch in #22 plus fix from #2754667-2: "In none of" (= Off/0) filter operator stopped working after Views update to 7.x-3.14 . This needs work; see @jcnventura's comment in #54.

I don't think this qualifies as critical now that original commit has been reverted.