This patch extends views_query.inc, so that it's possible to set a table alias prefix, which will be used for creating the query.

This offers no real new functionality itself, however I need this for doing tabular views, which list information, which is stored in different nodes. I've written a module called 'views_fusion' to achieve this.
It does its work in hook_views_query_alter(), however it needs the table aliases prefixes to work.

You can find more information about the views_fusion module here

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago’s picture

patch attached...

moshe weitzman’s picture

views_fusion looks pretty neat. i'd like to see fago get this functionality as proposed here, or in some other way. i can't really say if this is the best approach or not.

fago’s picture

first I tried to do it with one view - add all fields there and let views join the node tables appropriate.
quite hard to do and not so flexible, as I described here.

So I started with views fusion ;)

however any better approach is welcome..

eaton’s picture

I ran into something similar with votingapi integration.

Would this patch make it possible to add, say, three instances of a field to a single view, each with a different table alias? That would certainly make the work with votingapi integration a lot simpler.

fago’s picture

what do you mean exactly?

three instances of the same field which belong to the same node? no.. this doesn't change any UI.
three instances of the same field which belong to different nodes? yes, with views_fusion.
three instances of the same table, added through code? already possible without the patch.

or do you mean offering three different instances of the same table through hook_views_table?
yeah this should be better now, as you may define an alias for the left and another for the new table. actually the views_fusion module does this with the node table.

fago’s picture

I added correct handling of external filters for the views_fusion.module and fixed an issue with query caching,
however I needed a small change of views to achieve each.

hopefully they are ok in that way i made them?

a short description of both changes:

external filter change
it's possible to set a offset for the $count used for identifing the filter ops. most likely only needed by my module.. however a small change and a important feature...

query cache change
it's possible to prevent caching through setting $view->no_cache. I set this value with views_fusion through hook_form_alter() when a view is edited, when caching shall be avoided due to the fusion.

new patch attached

merlinofchaos’s picture

Okay, I've *finally* reviewed this, and here are the issues I have:

1) The setting of use_table_prefix from the view to the query is awkward and not in the style of the query object. It should either be passed in through the constructor or $query->set_table_alias_prefix

2) There's a global one as well as a per-table one. Do you really need both?

fago’s picture

Thanks for looking on this :)

ad 1)
I've create a set-function for this. new patch attached.

ad 2)
yes. the global one is needed to generate the query of a view with the aliasprefixes, so that the aliases don't clash. then the per-table one is needed to join tables of two different views.

further I can't use the per-table one instead of the global one, because each table might be used in more than one view and so it might get more than one different aliases.

fago’s picture

I've done some further work on this. Finally I changed the query class to take the alias_prefix in the constructor - so the standard node.nid field will be aliased too. Furthermore the aliases were missing inside the add_orderby() method.

Owen Barton’s picture

Any further review on this?
I have been using the latest patch and it seems to work great - views_fusion is really handy, and it would be great to support this!

merlinofchaos’s picture

Status: Needs review » Fixed

Committed to HEAD for testing purposes. Do you think you'll want this for 4.7? (I'm inclined to not add more features to 4.7 at this time)

fago’s picture

really great :)

A 4.7 version would be great, as views_fusion is written for 4.7. (I'll update it for 5.0 soon)

Anonymous’s picture

Status: Fixed » Closed (fixed)
bluecobalt’s picture

Has this been fixed in the 4.7 version of views so that views fusion works?

If not, which of the patches do I need to apply?

I can't get a views fusion to display. I get a blank page.

thanks,
blue

bluecobalt’s picture

Status: Closed (fixed) » Active

changing status to active

fago’s picture

no, that's not in views 4.7

I've attached an updated patch for views 4.7

bluecobalt’s picture

Hey Wolfgang,

I tried to apply the views_alias_prefix_5.patch to the latest version of views (views 4.7.x-1.1) that I just downloaded, and this is what happened:

patching file views.module
Hunk #1 FAILED at 1.
1 out of 2 hunks FAILED -- saving rejects to file views.module.rej
patching file views_query.inc
Hunk #1 FAILED at 1.
Hunk #3 succeeded at 90 (offset -1 lines).
Hunk #4 FAILED at 110.
Hunk #6 succeeded at 161 (offset -1 lines).
Hunk #7 FAILED at 195.
Hunk #9 succeeded at 275 (offset -1 lines).
Hunk #10 FAILED at 307.
Hunk #11 FAILED at 367.
Hunk #12 FAILED at 382.
Hunk #14 succeeded at 521 (offset -1 lines).
Hunk #15 FAILED at 546.
7 out of 15 hunks FAILED -- saving rejects to file views_query.inc.rej

Was this patch rolled against views 4.7.x-1.1?

thanks,
blue

fago’s picture

hm, strange this patch broke somehow.

anyway, here is a new patch - verified to work with the views 4.7 1.1 release.
this patch incorporates a new improvment

Be sure to use the latest views_fusion module with this patch!

merlinofchaos’s picture

Status: Active » Fixed

Applied to DRUPAL-4-7 trunk. fago, I'd like you to confirm that it's all working right before I roll this into the Views 1.2 release.

fago’s picture

yep, views fusion 4.7 works fine without any patching. great! thanks :)

newdru’s picture

As of Dec 2, Can i just download views.module tag "DRUPAL-4-7 Trunk" off the CVS tree instead of patching the file by hand?

Or are there other file dependencies that need to come down with views.module?

merlinofchaos’s picture

You should be able to download DRUPAL-4-7 (the 4.7.x-1.x-dev tarball) and there's a bug I need to roll a new release about so I want to try and get a 1.2 release out today if I can.

newdru’s picture

It looks like you upgraded the latest tarball on the views module page (not cvs) to the 1.2 version already.

When i untar it, the final modules directory is "views_1"...

Just to be sure.. you don't want users to install "views_1" folder into the active modules directory along WITH "view" folder but to REPLACE it (e.g. it's not meant to coexist with "view" but actually replace it) .. right?

newdru’s picture

1) I went in and moved the original old views out of the production modules directory..
2) I copied "views_1" into the production modules directory as "views"
3) copied in nodefamily module
4) copied in views fusion
5) admin/modules -> enabled nodefamil and views_fusion + Save (Save also helps reset/insure the new views module code is picked up - from what i can tell from the documentation (can anyone confirm this)?
6) refresh my cache via devel module (probably another way as well)

Can someone confirm i've applied the update the right way to insure the new 1.2 views is overriding (actually now that i think of it, it has to be because it's the only views code in my module directory since i moved the old views directory out)?

I've created two views:
- one for CCK Events
- one for CCK Venues

Then I

- admin/settings/nodefamily -> i make Events a parent of Venues

Then in admin/views

- i create a separate view for CCK Events "myevents" and filter by type Events
- i create a separate view for CCK Venues "myvenues" and filter by type Venues

Both work correctly on their own

Then I admin/views/fusion

- i create a new fusion
- Primary is myevents
- Fused view is myvenues

Results:

I go to show myevents (which should now have a myvenues fused to it) but myvenues never gets joined to myevents????? (actually not even field labels for any of the joined fields from the venues CCK are spit out in the table header list view that is supposed to contained the fused venue)

FYI:

- i've tried creating and recreating the views and the nodefamily relationship and the views fusion a number of times to no avail (in fact there seemed to be some inconsistency where delting a fuse actually wound up deleting the nodefamily relationship???? and then altering the view that had originally been saved?? i wish i could be more specific about this but i didn't take sufficient notes. there might be some bugs in the code, i may installed the new 1.2 incorrectly or just using this stuff incorrectly? just thought i'd give a heads up.
- i've tried flushing the cache many times in my regression testing here and it has made no difference.
- the nodefamily table looks correct in my db and is associating correctly between the two CCK types
- when i look at my trace on the fused view, it looks like it's not executing the second fused view....

Test 2:

- I recreate "myevents" view from scratch and call it "cloneevent"
- i recreate a fuse between "cloneevent" and "myvenues"

Result:

- it gives an error:
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:\wamp\www\drupal474\sites\default\modules\views_fusion\views_fusion.module on line 374

That's quite odd because that fuse is exactly identical to the first fuse i created except the first one half works????

FYI: this is in regards to http://drupal.org/node/100136

I've checked the nodefamily author's site at http://more.zites.net/soc/views_fusion..
It looks like i "should' be able to do what i want to do based on his example.

I'm wondering if i installed views 1.2 incorrectly?
If not there might be a bug in nodefamily / views_fusion?

If the author of nodefamily would be so kind to reply here or on my post as to whether or not nodefamily/views_fusion "should" solve my problem that would be greatly appreciated so i don't waste time trying to solve a problem these don't provide solutions for..

thanks

newdru’s picture

Status: Fixed » Active

Regarding last post: it looks as if the "cloneevents" view is NOT ACTUALLY writing "query" and "querycount" fields to view_view table..
eventhough when i edit the actual "eventsclone" view panel, the filters, fields, etc exits.

However, when it's not attached to a child fuse view it's still executing (the query that is derived from what i've set in the options for that view) and displaying as it should????

Something must be getting cached - but what? I've cleared the cache a number of times.

fago’s picture

Status: Active » Fixed

this issue is fixed, as views 1.2 includes this patch. Use views 1.2 and views fusion will work.
Please don't post special views_fusion problems to this thread, use its own issue queue!

newdru: So pls create another issue for any follow ups. Try to edit and save your event view again.

Anonymous’s picture

Status: Fixed » Closed (fixed)