I have 2 tables with has many relationship: Users
and Tests
, an the join table generated with bake that associates both TestsUsers
.
In TestsUsers
, I have 2 extra fields (besides user_id
and test_id
) named score
and date
. For adding a record for the first time, I manually crafted the entity in TestsController
(creating a $test
entity adding test.id
, user.id
, and user._joinData
) and used link()
for saving the data.
I'm having trouble in retrieving that record for editing. So far, in the index view (shows all records and has edit and delete actions), I'm passing 3 parameters to the edit function: test_id
, user_id
and TestsUsers_id
.
I've used:
$this->Tests->get(($test_id), [
'contain' => 'Users',
function ($q) use ($user_id) {
return $q->where(['Users.id' => $user_id])
}
]])
and the result is:
test
(test info)
users
[0]
user_id=1
(user info)
_joinData
id=1
[1]
user_id=1
(user info)
_joinData
id=2
The question is, how do I access _joinData
level in get()
for using its id.
P.S. = I'm not allowed to load or use the TestsUsers
model.
Thanks