Hello. I am enjoying Vokuro and have been trying some things using it as a base on my own, just to get used to the framework. I am enjoying it quite a lot. I have added a couple more tables and thus models on my own. I added a Communities model and am joining that to the Users model by means of a join table, CommunityUsers. I have created a model for this as well and have set up the relationships as recommended by the docs and other posts in the forums. However, while I can pull Users communities, I cannot pull results from Communities to get Community Users. So the relationship seems to only work one way -> from Users.
Here's the Communities model code:
<?php
namespace Vokuro\Models;
use Phalcon\Mvc\Model;
class Communities extends Model
{
...
public function initalize(){
$this->hasManyToMany(
"id",
"Vokuro\Models\CommunityUsers",
"community_id", "user_id",
"Vokuro\Models\Users",
"id",
array('alias' => 'users')
);
$this->belongsTo("client_id", "Clients", "id");
}
}
And here's my linked CommunityUsers Model:
<?php
namespace Vokuro\Models;
use Phalcon\Mvc\Model;
class CommunityUsers extends Model
{
public function initialize()
{
$this->setSource('community_users');
$this->belongsTo('community_id', 'Vokuro\Models\Communities', 'id', array(
'alias' => 'community'
));
$this->belongsTo('user_id', 'Vokuro\Models\Users', 'id', array(
'alias' => 'users'
));
}
}
And finally, the Users (abbreviated model only association shown):
<?php
$this->hasManyToMany(
"id",
"Vokuro\Models\CommunityUsers",
"user_id", "community_id",
"Vokuro\Models\Communities",
"id",
array('alias' => 'communities')
);
And the client code from the controller throwing the error (note the users call works fine, not the communities):
<?php
public function testAction(){
$users = Users::find();
foreach($users as $user){
$communities = $user->communities;
foreach($communities as $community){
echo $community->c_name;
}
}
$communities = Communities::find();
foreach($communities as $community){
$users = $community->users;
foreach($users as $user){
echo $user->name;
}
}
die();
}