Currently, When Ctools is building relationship contexts from fields, it assumes that the keys in the field schema will be the same as the entity id key from the entity it references. For example it assumes this:
array(
// ...
'foreign keys' => array(
'node_reference' => array( // some join identifier
'table' => 'node', // entity table
'columns' => array('nid' => 'nid'), // entity id key, relating field key
),
),
);
However, the relating field key can be arbitrarily named something different (such would be the case for Entity Reference):
array(
// ...
'foreign keys' => array(
'node_reference' => array( // some join identifier
'table' => 'node', // entity table
'columns' => array('nid' => 'target_id'), // entity id key, relating field key
),
),
);
The provided patch will use the foreign keys provided by the field to determine which key to reference for building the relationship context. I have tested this across custom field types with foreign keys, References module, and a patched copy of Entity Reference. #1340748: Add CTools relationship also depends on this.
Comments
Comment #1
helior commentedPatch
Comment #2
helior commentedAs suggested by EclipseGc, I added a static cache in ctools_field_foreign_keys() for performance.
Also, it might seem like a bigger patch because I was able to remove an if statement and shift over a huge block of code over.
Comment #3
merlinofchaos commentedI fear that my patching spree today has made this patch not apply.
Can you reroll this?
Comment #4
helior commentedHere's an updated patch.
Comment #5
aspilicious commentedI'm not sure how much merlin cares about trailing whitespaces but this patch has some.
Comment #6
merlinofchaos commentedI do care about trailing whitespace but I can also convince my editor to remove it for me.
Still it's best if patches can be posted without it. I don't always remember to do it.
Comment #7
helior commentedI'm curious as to what tools you both use to track white spaces. Regex? Some plugin or feature in your editors? Simply passing it through the Coder module?
Comment #8
aspilicious commentedDreditor: http://drupal.org/project/dreditor
and any good text editor can strip whitespaces on save. (with some configuration)
Comment #9
helior commentedThanks for the tip aspilicious! :)
Hope this one is better.
Comment #10
helior commentedOh, and in case anyone else is also curious about this, here's a macro I found for Textmate to remove white space on save. Handy!
http://mjijackson.com/2009/01/textmate-macro-remove-trailing-space-and-save
Comment #11
damien tournoud commentedSeems that this patch is related to #1418740: Entity from field relationship plugin should check the target column rather than the source column. I'm unclear on what the exact relationship between the two is.
Comment #12
fabsor commentedI'm coming from #1418740: Entity from field relationship plugin should check the target column rather than the source column, where I found another issue with the current implementation. I think both approaches needs to be incorporated in one patch to actually get this working properly (at least for me). The attached patch is a combination of #1418740 and the patch posted in #9, and it works well for me in NodeStream where we have a lot of entity reference fields.
Comment #13
karens commentedI tried this out using the latest development version of Entity Reference and the latest development version of CTools. Without this patch, there is no way to add a relationship for an entity reference to a Page Manager panel. With the patch the relationship shows up and works correctly.
Comment #14
henrijs.seso commentedKarenS is right. Tested this too.
Comment #15
merlinofchaos commentedCommitted! Thanks for the work and the testing!