bolt / bolt

Bolt is a simple CMS written in PHP. It is based on Silex and Symfony components, uses Twig and either SQLite, MySQL or PostgreSQL.
MIT License
4.15k stars 811 forks source link

[3.6][BUG][New Storage] record.related() returns array of Relations entities instead of real entities #7674

Open JarJak opened 5 years ago

JarJak commented 5 years ago

According to the docs: To get the actual related records, use the function related()

But it never happens.

Consider there is a relation maintype -> relatedtype.

If you call {{ dump(mainrecord.related('relatedtype')) }} you get Bolt\Storage\Collection\LazyCollection<Bolt\Storage\EntityProxy>

If you call it from reverse side {{ dump(relatedrecord.related('maintype')) }} you get ArrayIterator<Bolt\Storage\Entity\Relations>

What about record.relation then?

If you call {{ dump(mainrecord.relation) }} you get Bolt\Storage\Collection\Relations<Bolt\Storage\Entity\Relations>

If you call {{ dump(mainrecord.relation.relatedtype) }} you get an error.

/cc @rossriley

rossriley commented 5 years ago

The lazy collection is still the array of entities, you can iterate and use them as normal, just that they are loaded just in time.

  {% for page in records.related('pages') %}
     {{ dump(page) }}
  {% endfor %}

This will give you an actual instance of Entity\Content as expected

We can possibly look at changing this behaviour, the plan is to make the loading strategy configurable and I have a WIP branch for this but it's going to target a follow-up release since it was too big a feature to be finished in time for 3.6

JarJak commented 5 years ago

@rossriley thanks, it works :) However, how can I get it from inverse side of relation?

If you call it from reverse side {{ dump(relatedrecord.related('maintype')) }} you get ArrayIterator<Bolt\Storage\Entity\Relations>

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. Maybe this issue has been fixed in a recent release, or perhaps it is not affecting a lot of people? It will be closed if no further activity occurs, because we like to keep the issue queue concise and actual. If you think this issue is still relevant, please let us know. Especially if you’d like to help resolve the issue, either by helping us pinpointing the cause of a bug, or in implementing a fix or new feature.

JarJak commented 5 years ago

dont!

bobdenotter commented 5 years ago

Added 'keep' :-)