-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[NFR] Multiple Modules Models Alias and leftJoin #1111
Comments
You can use multiple joins from the same model just like you wrote.
If this is not the case of your question please describe more clearly ;) |
@jodator |
Ah, OK. I didn't use multi modules structure before. But if Phalcon is not using aliases then it would be nice if it does use them. |
@jodator Now i am porting big application more then 30k lines from zf1+doctrine1 to phalcon and now have big problem with no leftjoin on alias and 100500 select query on primary key when i use relations. $products = \Product\Model\Products\Table::find()**; // 1 select for 10 products
foreach($products as $product)
{
echo $product->User->username; // 1 select for alias User
} Total 1*10 + 1 =11selects |
I think you can use something like this: <?php
namespace Model\Extreme;
class ProfileNote extends \Phalcon\Mvc\Model
{
public $id;
public $user_id;
public $notes;
public $added_by;
public $dt;
public $edited_by;
public $edited_dt;
/**
* @return string
* @global $wpdb
*/
public function getSource()
{
global $wpdb;
return $wpdb->prefix . 'em_profile_notes';
}
public function initialize()
{
$this->belongsTo('user_id', '\\Model\\WordPress\\User', 'ID', array('alias' => 'User'));
$this->belongsTo('added_by', '\\Model\\WordPress\\User', 'ID', array('alias' => 'Creator'));
$this->belongsTo('edited_by', '\\Model\\WordPress\\User', 'ID', array('alias' => 'Editor'));
}
public static function getComments($user_id)
{
$di = \Phalcon\DI::getDefault();
$mgr = $di->get('modelsManager');
$phql = "
SELECT Note.*, Creator.*, Editor.*
FROM \\Model\\Extreme\\ProfileNote AS Note
LEFT JOIN \\Model\\WordPress\\User AS Creator ON added_by = Creator.ID
LEFT JOIN \\Model\\WordPress\\User AS Editor ON edited_by = Editor.ID
WHERE user_id = ?0
ORDER BY dt
";
return $mgr->executeQuery($phql, array(0 => $user_id));
}
} |
@sjinks Cпасибо за подсказку но было бы тут одно такое место да. а когда тут 50 таблиц куча сущностей и еще большей связей нельзя так делать. а еще в моделях есть метод $this->getModelsManager() )) |
А QueryBuilder заюзать не вариант? |
@sjinks Там в 1 аргументе нельзя использовать алиас он думает что это имя модели + надо дописывать связь и алиас в итоге это избыточно + он еще делает как я понимаю алиас токо для запроса а модель захочет использовать так $even->{"\User\Model\User"}; |
Could anyone implement this? |
Now i am porting profiler from PhalconEye cms to current project on phalcon ->leftJoin('Product\Model\Product', 'e.product_id = Product.id', 'Product')
->leftJoin('User\Model\Shop', 'Product.shop_id = Shop.id', 'Shop') But on foreach phalcon use select. @phalcon It's really just a wild hole in ORM. While such things will not work excellent library can throw. People do not need a super fast framework that can`t perform 1 query and makes sense from hundreds of such a framework = zero.90% application work time is ORM not MVC and etc |
Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues |
Hi all,
I have model
I would like to use
On Forum http://forum.phalconphp.com/discussion/766/multiple-relations-and-left-joind-models
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: