# |
Jun 27th 2017, 15:19 |
neon1024 |
save() returns mixed if I recall, false or the data |
# |
Jun 27th 2017, 15:19 |
neon1024 |
I would imagine that set() and link() return boolean as they’re just assigning things, so the boolean would be a ‘Yes Ive done this’ type return |
# |
Jun 27th 2017, 15:18 |
elboletaire |
btw, either case works for me :( any ideas on why this apparently works (both `save` using `set` and `link` always return true), but it really doesn't? |
# |
Jun 27th 2017, 15:17 |
elboletaire |
it's a bit more complicated than that... but it does internally `set` the related entities, and then runs `saveLinks` |
# |
Jun 27th 2017, 15:17 |
neon1024 |
Oh right, okay :slightly_smiling_face: |
# |
Jun 27th 2017, 15:17 |
elboletaire |
in fact, `link` does that internally afaik |
# |
Jun 27th 2017, 15:16 |
elboletaire |
doesn't work either using `set` |
# |
Jun 27th 2017, 15:16 |
neon1024 |
It’s the default too I think |
# |
Jun 27th 2017, 15:16 |
neon1024 |
Cool, that’s the one I prefer. I find it simpler to deal with |
# |
Jun 27th 2017, 15:16 |
elboletaire |
I've it in replace |
# |
Jun 27th 2017, 15:16 |
neon1024 |
Probably worth checking the association saveStrategy too just in case |
# |
Jun 27th 2017, 15:15 |
neon1024 |
Yep, and I would then expect it to create the join table records |
# |
Jun 27th 2017, 15:15 |
elboletaire |
after `set` I should save the entity, right? |
# |
Jun 27th 2017, 15:15 |
elboletaire |
hhmm I'll give it a try |
# |
Jun 27th 2017, 15:15 |
neon1024 |
I’d probably get a list of role entities, and set it to user $user->set(‘roles’ => $arrayOfRoleEntities); |
# |
Jun 27th 2017, 15:15 |
elboletaire |
how would you do this? linking existing entities with others before/after save? |
# |
Jun 27th 2017, 15:14 |
neon1024 |
Sorry @elboletaire I’ve never used `link()` before, so can’t help with that :slightly_smiling_face: |
# |
Jun 27th 2017, 15:10 |
slackebot |
success. Any ideas on what's failing? The piece of code is something like this: ```$roles = $entity->roles; $users = $this->Users->find()->where(['department_id' => $entity->id])->all(); foreach ($users as $user) { $this->Users->Roles->link($user, $roles); } ``` |
# |
Jun 27th 2017, 15:10 |
elboletaire |
I'm trying to link belongstomany models using `link`, and, despite it always returns true, does nothing. I'm trying to relate roles with users (Users belongsToMany Roles and vice-versa) using `$this->Users->Roles->link($user, $roles)` where `$roles` is an array of existing role entities and `$user` is the user I'm trying to link to that roles. I'm doing this on another's table `afterSave` method, but I've also tried it directly in the con |
# |
Jun 27th 2017, 14:49 |
neon1024 |
https://github.com/cakephp/app/blob/master/config/app.default.php#L249 |
# |
Jun 27th 2017, 14:49 |
neon1024 |
You need to enable the quote identifiers |
# |
Jun 27th 2017, 14:49 |
gutts_ |
or should I just revert back to start/end |
# |
Jun 27th 2017, 14:49 |
gutts_ |
does cake not escape/wrap `s around columns? if have 'from' and 'to' as column names, the update/insert doesnt work.. sql log has SET from = '2017-06-27'. is there some escaping setting for this? |
# |
Jun 27th 2017, 14:35 |
admad |
bingo! x) |
# |
Jun 27th 2017, 14:35 |
jeremyharris |
I’m guessing “mad” :) |
# |
Jun 27th 2017, 14:34 |
neon1024 |
Heh |
# |
Jun 27th 2017, 14:34 |
jeremyharris |
how does that make you FEEL, @admad |
# |
Jun 27th 2017, 14:34 |
admad |
this open source tech support, not therapy session with your shrink :P |
# |
Jun 27th 2017, 14:32 |
jeremyharris |
talk it out, friend |
# |
Jun 27th 2017, 14:31 |
neon1024 |
Yes, I haven’t got ‘on’ => ‘create’ perhaps |
# |
Jun 27th 2017, 14:30 |
neon1024 |
Er, my association is validating the parent foreign key I mean |
# |
Jun 27th 2017, 14:30 |
neon1024 |
Could it be that my associations requires the foreign key, but it’s an add, so there isn’t one |
# |
Jun 27th 2017, 14:28 |
neon1024 |
No, but that’s a good idea :slightly_smiling_face: |
# |
Jun 27th 2017, 14:27 |
jeremyharris |
@neon1024 it most certainly should, have you tried just creating the associated entity to see if it validates |
# |
Jun 27th 2017, 14:27 |
jeremyharris |
heh |
# |
Jun 27th 2017, 14:26 |
hmic |
it's really funny sometimes, as you type the answer in the same sentence you are typing the question... |
# |
Jun 27th 2017, 14:26 |
neon1024 |
Even more so today, only me and one designer in today |
# |
Jun 27th 2017, 14:26 |
hmic |
remaining 30% is off topic anyways :P |
# |
Jun 27th 2017, 14:26 |
neon1024 |
@hmic Too true lol! |
# |
Jun 27th 2017, 14:26 |
neon1024 |
Or is the parent’s errors array inclusive of the associated errors? |
# |
Jun 27th 2017, 14:26 |
hmic |
the other half is RTFM basically |