Relationships currently have to define the base table and field they join to in their hook_views_data().
However, there are a number of use case where a relationship that has a variable right hand table is useful: eg, Flag module joining the {flagging} table to the entity base table for the entity type that's being flagged. #1694956: define a views relationship from {flag_content} towards entities.
The base table is set in the definition for the following reasons:
1. the query() method makes use of the definition
2. the UI to add fields/filters/etc uses this to compile a list of base tables on the view, to know which handlers to show
3. the UI for a handler's options uses this to compile a list of relationships on the view that the handler may be placed on
1 can be sidestepped by a custom relationship handler. 2 can be sidestepped by the handler class's init() method setting the right hand table and field in $this->definition.
3 however doesn't work, because the handler's init() is called slightly too late.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1748480.views_.variable-relationships-rhs.patch | 913 bytes | joachim |
Comments
Comment #1
joachim CreditAttribution: joachim commentedWith this patch, my custom relationship handler class can do this:
and not need to set these in hook_views_data(). Thus in theory these could be picked up from the handler options.
Comment #2
joachim CreditAttribution: joachim commentedIt turns out that step 1 is not even necessary -- if the init() spoofs the base table and field, the query() is none the wiser and works as normal!
There's a working patch at #1694956: define a views relationship from {flag_content} towards entities that makes use of the patch here to provide a variable-base relationship from the {flagging} table to whichever entity the flag is on.
Comment #3
diwant CreditAttribution: diwant commentedI came here from a Userpoints issue (http://drupal.org/node/1668498). I don't understand enough about views and userpoints to know if this is what that issue needs. Can someone who knows a bit more about views/userpoints shed some light please?
Comment #3.0
joachim CreditAttribution: joachim commentedUpdated issue summary.
Comment #4
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 6 year old patch to admin.inc applied cleanly to the latest views 7.x-3.x-dev and if still applicable needs to be reviewed.