{"action":"opened","issue":{"url":"https://api.github.com/repos/OmgDef/yii2-multilingual-behavior/issues/7","labels_url":"https://api.github.com/repos/OmgDef/yii2-multilingual-behavior/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/OmgDef/yii2-multilingual-behavior/issues/7/comments","events_url":"https://api.github.com/repos/OmgDef/yii2-multilingual-behavior/issues/7/events","html_url":"https://github.com/OmgDef/yii2-multilingual-behavior/issues/7","id":56567370,"number":7,"title":"Few bugs (repeated queries)","user":{"login":"andreCatita","id":2508009,"avatar_url":"https://avatars.githubusercontent.com/u/2508009?v=3","gravatar_id":"","url":"https://api.github.com/users/andreCatita","html_url":"https://github.com/andreCatita","followers_url":"https://api.github.com/users/andreCatita/followers","following_url":"https://api.github.com/users/andreCatita/following{/other_user}","gists_url":"https://api.github.com/users/andreCatita/gists{/gist_id}","starred_url":"https://api.github.com/users/andreCatita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreCatita/subscriptions","organizations_url":"https://api.github.com/users/andreCatita/orgs","repos_url":"https://api.github.com/users/andreCatita/repos","events_url":"https://api.github.com/users/andreCatita/events{/privacy}","received_events_url":"https://api.github.com/users/andreCatita/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-04T18:30:17Z","updated_at":"2015-02-04T18:30:17Z","closed_at":null,"body":"Hello @OmgDef \r\n\r\nFirst all, good job so far.\r\nI would like to point out a few things:\r\n\r\nIn your usages examples #1\r\n```\r\n//Assuming current language is english\r\n$model = Post::findOne(1);\r\necho $model->title; //echo \"English title\"\r\n//Now let's imagine current language is french \r\n$model = Post::findOne(1);\r\necho $model->title; //echo \"Titre en Français\"\r\n$model = Post::find()->localized('en')->one();\r\necho $model->title; //echo \"English title\"\r\n//Current language is still french here\r\n```\r\nThis works, but from what I understood from a recent mail exchange we had, I thought the default Language wasn't supposed to go search for translation in PostLang, it would just use the Post for the default language.\r\nBut I was able to fix that, in your MultilingualTrait, here is what I can't fix, or figure out why:\r\n\r\nIf after that example #1 of yours, I do the following:\r\n```\r\n$model = Post::find()->where(['id' => 1])->multilingual()->one();\r\n```\r\n\r\nThe MultilingualTrait performs this query correctly, ie: SELECT * FROM PostLang WHERE post_id=1\r\nIt will also repeat the last find query, in your example #1, it means it would repeat a query to PostLang, searching for 'en'.\r\n\r\nHere is my sequence with my 'Products' model:\r\n\r\n```\r\n$model = Products::findOne(1);\r\necho \"<br>\";\r\necho \"findOne (default language pt) title: \" . $model->title;\r\necho \"<br>\";\r\n\\Yii::$app->language = 'en';\r\n$model = Products::findOne(1);\r\necho \"<br>\";\r\necho \"findOne (default language en) title: \" . $model->title;\r\necho \"<br>\";\r\n\\Yii::$app->language = 'fr';\r\n$model = Products::findOne(1);\r\necho \"<br>\";\r\necho \"findOne (default language fr) title: \" . $model->title;\r\necho \"<br>\";\r\n$model = Products::find()->where(['id_product' => 1])->multilingual()->one();\r\necho \"<br>\";\r\necho \"findMultiLingual title: \" . $model->title;\r\necho \"<br>\";\r\necho \"findMultiLingual title_en: \" . $model->title_en;\r\necho \"<br>\";\r\necho \"findMultiLingual title_fr: \" . $model->title_fr;\r\n```\r\n\r\nI hoped this would result in 4 queries.\r\nWithout changing anything, by default your extension performs 6 queries.\r\nTaken I'm testing with 'pt', 'en' and 'fr'.\r\nHe queries Products and ProductsLang for 'pt' ( 2 queries ) -> This one I was able to fix.\r\nHe then queries ProductsLang for 'en' and 'fr' ( 2 queries )\r\n** He then queries ProductsLang (without lang for multilingual ) ( 1 query)\r\n** At this point is when he repeats the query for the last findOne, which in this sequence was the 'fr' one..\r\n\r\n"}}