Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

[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 ```txt bool(true) bool(false) ```

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

Phalcon version 1.3.0



81.8k

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



7.5k
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.



81.8k
Accepted
answer

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



7.5k

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