Posted by wjaspers on October 11, 2010 at 5:30pm
I'm working on adding some functionality to a module I'd like to launch my company's site with, but it lacked views integration. I have almost all of the integration done, but I've hit a wall.
How do you grab a field from another table in hook_views_data()?
I've found documentation on how to create the relationship, but not how to alias the field or how to group the field as part of the current module.
Any suggestions? Thanks for your help!
Comments
No takers, huh? No worries --
No takers, huh? No worries -- i solved most of my troubles thus far.
Is it possible or do I have to override a handler to mask Node ID when it is used in another table?
A few hints
I'm short on example code as I still have some issues with mastering Views API, but since no one has answered I can point you a little more in the right direction.
Depends. If the other table is somewhere in the drupal db, you need to views enable that table. Some Drupal data is views enabled but not everything. Certainly not all Drupal modules are Views aware.
If the other table is in another db (not Drupal's) but is still on the same physical machine, you should be able to views enable that table and join it using table prefix set to table name (exploits MySQL's ability to select across DBs). If the db is on another machine, there's no supported method.
As another approach, you can always write a custom views handler that does custom SQL (or anything, really) on the backend and returns a datafield to Views.
I think the reason that no
I think the reason that no one has answered your question is that it does not make sense. You don't grab fields or tables in hook_views_data(), you do it it in handlers. In hook_views_data() you are simply describing how fields on tables are handled.
This may help
http://treehouseagency.com/blog/neil-hastings/2010/01/19/views-handler-e...
also:
http://www.drupalove.com/article/100-drupal-views-tutorials-and-resources