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
| Comment | File | Size | Author |
|---|---|---|---|
| #56 | views-additional_field_to_field-1090432-56.patch | 5.04 KB | othermachines |
| #2 | additional-field-to-field-conditions-1090432-3.patch | 2.46 KB | fubhy |
Comments
Comment #1
dawehnerCan 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.
Comment #2
fubhy commentedHere is the patch for 7.x-3.x
Comment #3
merlinofchaos commentedOk, this looks reasonable to me. CanI get one for 6.x-3.x too?
Comment #4
fubhy commentedDone for 6.x-3.x. Couldn't test it yet but the code is the same as for 7.x-3.x.
Comment #5
dawehnerI'm sorry but the patch doesn't apply anymore against 7.x-3.x
Comment #6
fubhy commentedI will fix that later tonight! Thanks for the heads-up
Comment #7
dawehnerMan what a long night :)
Subscribe to this issue because i would like to have this issue in
Comment #8
fubhy commentedWhoops... Same with the other Issue :P. Fixing it NOW!
Comment #9
fubhy commentedThe 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!
Comment #10
fubhy commentedThe 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!
Comment #11
derhasi commentedFor #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
formulainfo, so more complex on clauses could be managed.Examples:
fubhy, dereine, do you think this will be a useful addition.
Sure, additional documentation was needed for the new functionality.
Comment #12
dawehnerViews in drupal6 has
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.
Comment #13
tim.plunkettTriggering the testbot.
Comment #14
rudiedirkx commentedOeh 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.
Comment #15
johnv@derhasi , your patch #11 contains 2 files. Which is the one to apply?
Comment #16
rudiedirkx commented@johnv
additional-field-to-field-conditions-1090432-11.patchworked for me. (The first, big one.)If it's a simple join, use can use
left_fieldandleft_table. Otherwise, useformula.Comment #18
rudiedirkx commentedThat's the one.
Comment #19
it-cruRefactor patch from #11 against current code repo. Works for me with 7.x-3.8.
Comment #20
robertwb commentedPatch in #11 applies correctly and functions correctly in most recent git dev as of 2015/03/18.
Comment #21
colanWe'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.
Comment #22
rudiedirkx commentedComment #23
rudiedirkx commentedComment #25
colanThanks.
Comment #26
robertwb commentedHey @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).
Comment #27
robertwb commentedComment #29
maximpodorov commentedI have the problem mentioned in #26 also (with NOT IN filter).
Comment #30
maximpodorov commentedThe commit breaks existing sites with NOT IN filters. I suggest to revert it and find a non-destructive solution.
Comment #33
dawehner@maximpodorov I agree with you. Do you mind moving the issue back to views itself?
Comment #34
maximpodorov commentedComment #35
maximpodorov commentedSo the reverting patch is OK now.
Comment #36
gedur commentedThere 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!
Comment #37
hass commentedThis introduced a regression that breaks all JOINs. Please create a new STABLE views release asap.
Comment #38
sam152 commentedAfter 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.
Comment #39
sam152 commentedAttached is a revert patch.
Comment #41
joelpittet@Sam152 I think you just need the
--relativeflag on git when you created that patch from in the views folder in your project.Comment #42
sam152 commentedHand-fiddled patch.
Comment #43
rudiedirkx commentedReverting 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..
Comment #44
hass commentedIf a patch only causes issues we typically revert it.
Comment #45
sam152 commentedA 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?
Comment #46
jromine commentedThis introduced a regression that breaks extra with zero value #2791353: JOIN 'extra' fails with zero value
Comment #47
othermachines commentedAnother 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.
Comment #48
jcnventuraReverting this patch also fixed a problem introduced by 3.14.. Please commit the revert, until a test+fix can be committed again.
Comment #49
hass commentedFor about 7 months a broken views release is shown on project home. Are the maintainers alive?
Comment #50
othermachines commentedHere'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.
Comment #52
dawehnerI pushed the revert patch now. Thank you, well let's see whether someone is willing to work on the issue itself.
Comment #53
othermachines commentedThanks 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"?
Comment #54
jcnventura@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].
Comment #55
jcnventuraComment #56
othermachines commentedSorry, 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.