New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AR should apply LIMIT 1 when lazy loading HAS_ONE relations #1857
Comments
On my opinion, the issue is inconsistent. The "HAS_ONE" relation is the one, which supports value extraction from related table by the single query. If you run:
Active Record will fetch the data for “Item” and “Category” by the single query, like following:
If we satisfy the demand of this issue and allow to specify order and limit for the “HAS_ONE” relation, how we will resolve the “with” option? @tomtomsen, if you want to find latest comment for the post, you should declare the relation “posts” as “HAS_MANY” and then use the method notation on its lazy load:
|
Closed for the reasons explained. |
http://www.yiiframework.ru/forum/viewtopic.php?f=3&t=12859 array(‘order’=>’id DESC’, ‘limit’=>1) not working in model search() (not lazy load). Any solutions? |
There is not way to find “users” with their last “order” using eager loading. There is not SQL query which can perform such selection. |
In CGridView will be hundreds of SQL queries.. |
In your particular case you may attempt to solve the situation using “denormalize” approach. |
I thought about this solution, but it is not very good: ( |
Sorry, but there is nothing else I could advise you. |
Post relation:
Controller:
SQL generated:
Since we need only one record
LIMIT 1
should be applied.Very minimal test application:
http://ds.rmcreative.ru/ar_has_one_limit_issue.zip
The text was updated successfully, but these errors were encountered: