Phalcon version 1.2.4
class Server extends \Phalcon\Mvc\Model {
public function initialize() {
$this->hasManyToMany(
'server_id', 'ServersSubscriptions', 'server_id', 'subscription_id', 'Subscription', 'subscription_id',
array('alias' => 'subscriptions')
)
};
public function getSource() {
return 'servers';
}
}
class ServersSubscriptions extends \Phalcon\Mvc\Model {
public function initialize() {
$this->belongsTo('server_id', 'Server', 'server_id');
$this->belongsTo('subscription_id', 'Subscription', 'subscription_id');
}
public function getSource() {
return 'servers_subscriptions';
}
}
class Subscription extends \Phalcon\Mvc\Model {
public function initialize() {
$this->hasManyToMany(
'subscription_id', 'ServersSubscriptions', 'subscription_id', 'server_id', 'Server', 'server_id',
array('alias' => 'servers')
)
};
}
class Test {
public function run() {
$server = Server::findFirst(1);
$subscriptions = $server->subscriptions;
// result: $subscriptions is empty
$subscriptions = $server->getRelated('subscriptions', null);
// result: still empty
}
}
but ...
SELECT *
FROM subscriptions
INNER JOIN servers_subscriptions ON servers_subscriptions.subscription_id = subscriptions.subscription_id
WHERE servers_subscriptions.server_id = 1
returns one record, which is correct.
What am I doing wrong here?