Log message #4048246

# At Username Text
# Jul 5th 2017, 15:08 jeremyharris ah, cool. glad you got it working!
# Jul 5th 2017, 15:08 pedroseco thanks for pointing me on the right direction
# Jul 5th 2017, 15:08 pedroseco yes
# Jul 5th 2017, 15:05 jeremyharris does posts belongsToMany files too?
# Jul 5th 2017, 15:05 pedroseco and: $this->Posts->save($post,[‘associated’=>[‘Files._joinData’]])
# Jul 5th 2017, 15:05 pedroseco the array saved it.
# Jul 5th 2017, 15:05 pedroseco so instead of the newEntity like we tried: $this->request->data[‘files’][$c][‘file_id’] = $value; $this->request->data[‘files’][$c][‘_joinData’][‘sort’] = 2;
# Jul 5th 2017, 15:04 jeremyharris woohoo! what was it?
# Jul 5th 2017, 15:04 pedroseco @jeremyharris hey. got it too work :)
# Jul 5th 2017, 14:50 pedroseco thanks
# Jul 5th 2017, 14:47 jeremyharris you may want to debug the entity that is returned when doing a find from Files that includes Posts, that will show you the structure you need
# Jul 5th 2017, 14:46 pedroseco too bad I can’t use the proper belongsToMany association. It seems I always have problems with it
# Jul 5th 2017, 14:46 pedroseco ah no problem, we are always learning :slightly_smiling_face:
# Jul 5th 2017, 14:45 jeremyharris @pedroseco sorry about that. really thought the second example with the post id would marshal the way you needed it to
# Jul 5th 2017, 14:45 casmo gutts: Then you can add a function in your table like: function validName($value, $context) { debug($context); }
# Jul 5th 2017, 14:45 casmo gutts: What I meant is that if you wanna check a validation on a field e.g. 'name', you can do this (in validationDefault): $validator->add('name', 'custom', ['rule' => 'validName', 'provider' => 'table']);
# Jul 5th 2017, 14:44 pedroseco @jeremyharris naaa. I’m out of luck. Probably best save it manually into the Join table instead of trying to use the belongsToMany
# Jul 5th 2017, 14:44 casmo gutts: Sorry, had some stuff. Aren't you looking for https://book.cakephp.org/3.0/en/orm/validation.html#foreign-key-rules ?
# Jul 5th 2017, 14:38 pedroseco so be creating those new entities before i do the $this->Posts->save() i probably should append those into Posts too like you mentioned
# Jul 5th 2017, 14:36 jeremyharris then I think you want to include the id in the Posts array
# Jul 5th 2017, 14:36 pedroseco let me try it anyway.
# Jul 5th 2017, 14:36 jeremyharris hm
# Jul 5th 2017, 14:35 pedroseco probably not since the Posts model is the one who is doing the ->save() after
# Jul 5th 2017, 14:34 jeremyharris I think you want what’s in the second comment. There should be a post in there
# Jul 5th 2017, 14:34 pedroseco *Posts
# Jul 5th 2017, 14:34 pedroseco let me add the associated key _joinData into Poss
# Jul 5th 2017, 14:34 jeremyharris that’s from the first comment?
# Jul 5th 2017, 14:34 pedroseco yes i think thats it
# Jul 5th 2017, 14:34 pedroseco its already there, but it doesn’t get saved into database.
# Jul 5th 2017, 14:34 pedroseco with the result entity.
# Jul 5th 2017, 14:34 jeremyharris you might need to include Posts._joinData in the ‘associated’ key in the options to make sure it marshals. If you debug the entity and it’s missing association, that’s probably it
# Jul 5th 2017, 14:34 pedroseco ok so almost there, i made a comment too
# Jul 5th 2017, 14:33 jarard01 neon1024, I just tried hooking my Links model up to LinksImages and making it a hasMany relationship, it works so looks to be an issue - I'll create an issue of rit
# Jul 5th 2017, 14:33 jeremyharris I added another comment to what I think it should be
# Jul 5th 2017, 14:32 pedroseco let me try
# Jul 5th 2017, 14:31 pedroseco ah i see
# Jul 5th 2017, 14:31 pedroseco let me check, the association is Files belongsToMany Posts
# Jul 5th 2017, 14:29 jeremyharris (I think I’m missing the name of the joined association though
# Jul 5th 2017, 14:29 jeremyharris I added a comment on the gist
# Jul 5th 2017, 14:28 jeremyharris what I would do is make an array, and pass that into newEntity
# Jul 5th 2017, 14:28 jeremyharris yes, it needs to be an entity at that point