This took me a while to figure out, so I want to post it here for future searches.
In the documentation, the examples all use non-namespaced models, like "Robots" and "Parts". Most people (I think) will actually be using namespaced models, such as "Myapp\Models\Robots" and "Myapp\Models\Parts". For namespaced models like this, you have to provide the full namespaced name of the model when providing the relationship definition.
Then, and here's the most important part, perhaps: you define an alias so you don't have to type the full path every time you use the relationship.
Here's an example out of my app, in which I wrote a little documentation for myself so I'd remember how it has to work. In this example, I have defining a User model that has a n-n relationship with a Role modle, through a junction table called User_Role.
namespace Siecomp\Models;
use Phalcon\Mvc\Model\Validator\Uniqueness;
use Phalcon\DI;
class User extends SiecompModel
{
// ... properties ...
public function initialize()
{
$this->setSource('user');
// Roles relationship - n-n.
/**
* Signature of Phalcon's n-n definition so I don't have to look it up
* every time...
*
* @param string Name of the id property of this model
* @param string Full namespaced name of junction model
* @param string Name of the id property of this model in the junction model
* @param string Name of the id property of referenced model in the junction model
* @param string Full namespaced name of the related model
* @param string Name of the id property of the related model
* @param array Options; most important is 'alias', which will be the name
* of this relationship in getRelated methods.
* Examples:
* without alias: $user->getRelated('Siecomp\Models\Role')
* with alias (explicit): $user->getRelated('Roles')
* with alias (magic): $user->getRoles()
*
*/
$this->hasManyToMany(
'id',
'Siecomp\Models\Role_User',
'user_id',
'role_id',
'Siecomp\Models\Role',
'id',
array(
'alias' => 'Roles'
)
);
// Invites relationship - 1-n; any given user can create many invites
$this->hasMany('id', 'Siecomp\Models\Invite', 'creator_user_id');
}
// ... more methods ...
}