1

This might be a little complex, but here it goes:

Goal: For any given entry, determine where it's located. (Ex. Entry XYZ exists in a news entry, global field, single (page), etc...)

Context: So far I figured I could go the custom SQL route until I learned more about craft internals, so what I did was create a Service that does the following query:

    $query = craft()->db->createCommand()
        ->select('element.*, detail.type, relation.fieldId AS sectionId, section.handle, section.name, section.hasUrls')
        ->from('elements_i18n AS element')
        ->join('relations AS relation', 'relation.sourceId = element.elementId')
        ->join('elements AS detail', 'detail.id = element.elementId')
        ->join('sections AS section', 'section.id = relation.fieldId AND section.hasUrls = 1')
        ->where('relation.targetId = :id', array(
            ':id' => $elementID
        ));

    $results = $query->queryAll();
    $results = MyPlugin_EntryRelationshipModel::populateModels($results);

I'm using MyPlugin_EntryRelationshipModel as a Facade and it extends Craft\ElementCriteriaModel

Problem: This works flawlessly until a Matrix field comes into play.

3

So I found this: https://github.com/iainurquhart/craft_introvert which is exactly what I wanted to do. Hope this helps anyone else!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.