Replies: 3 comments 1 reply
|
Yeah, this'll be almost impossible to do, because Hyper doesn't store relationships in either its own database tables, or make use of the Craft We're absolutely looking into options to improve this, likely adding a relations table to handle this sort of thing. |
0 replies
|
I guess you could make a generated column to extract the element IDs from the JSON, and add an index to it that can be queried? Good to know you are looking into options, this would be a nice thing to have. |
1 reply
|
Updated in 3.0.0-beta.1. {% set owners = craft.hyper.getRelatedElements({
relatedTo: {
targetElement: element,
field: 'yourHyperFieldHandle',
},
elementType: 'craft\\elements\\Entry',
site: '*',
}).all() %} |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
My use case is a 'Used by' tab on Assets, using a custom template in the field layout. I'd like to be able to list all entries that are related to the asset via a Hyper field element relationship. This is straightforward to do for native element relationships, but I'm having a hard time working out how to query reverse relationships to Hyper fields.
{% set rels = craft.entries.relatedTo(element).siteId('*').collect() %} {% set owners = [] %} {% for rel in rels %} {% set owner = rel.owner ?? rel %} {% set owner = owner.primaryOwner ?? owner %} {% if owner.canonicalId not in owners %} {% set owners = owners + { (""~owner.canonicalId~"") : { cpEditUrl : owner.cpEditUrl, title : owner.title, site: owner.site.name, section: owner.section.name, canSave: owner.canSave(currentUser) } } %} {% endif %} {% endfor %} <div class="pane"> {% if owners|length %} <h2>This content is used by the following entr{{ owners|length == 1 ? 'y' : 'ies' }}:</h2> <ul style="list-style: square; margin-left: 1rem;"> {% for item in owners|sort((a, b) => a.title <=> b.title) %} <li> {% if item.canSave %} <a href="{{ item.cpEditUrl }}"> {{ item.title }} </a> {% else %} {{ item.title }} {% endif %} ({{ item.site }} ▸ {{ item.section }}) </li> {% endfor %} </ul> {% else %} <h2>This content appears to be unused by any entries at the moment</h2> {% endif %} </div>All reactions