We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

[BUG?] hasMany doesn't exist on model

When I call this (and other relation methods) method from behaviors (I have such a need), I get this message:

ValueError: Could not parse 'The method "hasMany" doesn't exist on model "Name\Space\Model"

at the same time:

die(var_dump($model instanceof Phalcon\Mvc\Model, method_exists("hasMany", get_class($model))));

produces

bool(true)
bool(false)

The inheritance is the following: Phalcon\Mvc\Model -> MyBaseModel -> MyModel

Phalcon version 1.3.0



98.9k

hasMany is a protected method so it cannot be called out of the model class scope.



12.2k
edited Oct '14

Any reasons on keeping it protected? I can still use (and I do)

$model->getModelsManager()->addHasMany("..", $model);

which is the same, but longer.



98.9k
Accepted
answer

Yes, it must be moved to public also: hasOne and belongsTo



12.2k

Thank you for clearance, I will create a ticket in Github regarding this.