cakephp - cakephp3 iterate hasMany associated entities -


we using new cakephp orm , have issues understanding way new orm works when dealing hasmany associations.

e.g. have table called "users" has hasmany relation table "usersabsences". definition , handling works fine. have defined table-objects , entities.

$this->addassociations([ 'hasmany' => [     'usersabsences' => [         'classname' => 'usersabsences',         'propertyname' => 'absences',         'foreignkey' => 'user_id'     ] ]); 

within our userstable we've created custom method retrieves details 1 user, using querybuilders ->contain method fetch hasmany-associated "usersabsences" defined property "absence". we're setting view-variable $user work entity in template: works fine.

... $users->contain(['usersabsences',...]); ... 

now part puzzles me: object-type of $user "userentity". when iterate through $user->absences... cakeentity objects, not (as expect) absenceentity-objects.

problem: implement custom method in userabsence-entity call in template when iterating through each absence of user.

when using ->contain method associations attached "belongsto", correct entity-class.

someone idea how deal that?

mind terminology, entity classes not have entity suffix, makes question little confusing, 1 might think you've named classes incorrectly! please use actual, ideally fully qualified classnames in questions!

that being said, default name of corresponding entity figured table class name, is, singular name without table suffix. so, userstable it's user, , usersabsencestable usersabsence, not absence.

so, renaming absence entity file/class usersabsence should fix problem. alternatively can manually define entity class table should use specifying via table::entityclass().

see also


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -