-
-
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
ModelsManager->getRelations doesn't return the many through relations #10839
Comments
<?php
$di = new Phalcon\DI();
$di->set(
'db',
new Phalcon\Db\Adapter\Pdo\Sqlite(
array(
"dbname" => "sample.db"
)
)
);
$di->set('modelsManager', new Phalcon\Mvc\Model\Manager());
// Use the memory meta-data adapter or other
$di->set('modelsMetadata', new Phalcon\Mvc\Model\Metadata\Memory());
class Event extends \Phalcon\Mvc\Model{
protected $id;
protected $user_id;
protected $text;
public function initialize(){
$this->belongsTo("user_id", "User", "id", ["alias"=>"user"]);
}
}
class User extends \Phalcon\Mvc\Model{
protected $id;
protected $name;
public function initialize(){
$this->hasManyToMany("id", "UserGroup", "user_id", "group_id", "Group", "id", ["alias"=>"groups"]);
$this->hasMany("id", "Events", "user_id", ["alias"=>"events"]);
}
}
class UserGroup extends \Phalcon\Mvc\Model{
protected $group_id;
protected $user_id;
}
class Group extends \Phalcon\Mvc\Model{
protected $id;
protected $name;
public function initialize(){
$this->hasManyToMany("id", "UserGroup", "group_id", "user_id", "User", "id", ["alias"=>"users"]);
}
}
// Result
var_dump((new User)->getModelsManager()->getRelations("User"));
// Many to many
var_dump((new User)->getModelsManager()->getHasManyToMany((new User)));
// Expected result for getRelations()
var_dump(array_merge((new User)->getModelsManager()->getRelations("User"), (new User)->getModelsManager()->getHasManyToMany((new User)))); Output
|
Any info? |
I'll try to sort out |
Hello, any info on this? It seems still present. |
This issue is open from more than 2 years but seems that no-one is interested on it. It could be solved by adding this piece of code in the getRelations method:
Meanwhile I made it working by extending the original ModelsManager and overriding the getRelations method in order to add the many-to-many relation to the returned list:
|
I just bumped into this as well. Your workaround works fine @idevelop4you. But obviously it would be nice if this was fixed. Ping: @sergeyklay |
Resolved in #14086 |
I think it's missing from phalcon/mvc/model/manager.zep getRelations function.
The text was updated successfully, but these errors were encountered: