Conversation
… and specifically their relations, whereas loading as method loads an querybuilder and loading as property loads a collection
|
I forgot about the test by the way 😄 |
|
Do we really need reflection? Doesn't this hurt performance? |
|
Reason for reflection is to check for a static method. Eloquent models can't handle them for us and to twig there is no difference. However simple calling Play around with the proposed code with the following scenarios: {% for item in model.items %}
{% endfor %}
{% for item in model.items.paginate(10) %}
{%endfor %}
{% for item in model.items().paginate(10) %}
{%endfor %}
{{ model.staticMethod }}
{{ model.simpleMethod }}Something like the above will prove the need to split. No idea whether the proposed check for static calls can be left out. The |
|
I'm rewriting to lose the reflection. Also seems like I opened up another bug somewhere. Murphy's jokes. |
|
By using |
|
Can you provide you model and template? I can't really replicate this with the latest 0.6-dev. I have this twig template: And a model with this relation, that currently has 3 items: And this is my result, which seems correct (second returns a query, so shouldn't work. |
|
@barryvdh current code on 0.6-beta fails on static methods. I just pushed a new version minifying everything to the base minimum. |
|
Did you compare this with beta3 of the dev-0.6@dev version (the code your now editing)? |
|
I'm not getting any results from the pagination at all with that the master 0.6-beta3 version. However I now do call the relation as a method and run pagination on that builder as well. Most likely this is not supported in that version? |
|
I'm not sure about beta3, I tested with the latest dev version, and it worked there. |
|
When using the latest branch 0.6 version any static method will run through the getAttribute method from the Eloquent model, where it will attempt to load the method as a relation, which fails on line 2379 of Eloquent\Model with an exception that the returned result is no relation. |
|
See #126 |
#126 fixed resolving of attributes in templates concerning eloquent models and specifically their relations, whereas loading as method loads an querybuilder and loading as property loads a collection