# |
Jul 5th 2017, 16:40 |
jarard01 |
sure |
# |
Jul 5th 2017, 16:40 |
jeremyharris |
jarard01 cool I’ll update my answer, if you can accept I’d appreciate it :slightly_smiling_face: |
# |
Jul 5th 2017, 16:39 |
pedroseco |
yes its the fk |
# |
Jul 5th 2017, 16:39 |
jeremyharris |
the join table fk? |
# |
Jul 5th 2017, 16:39 |
jarard01 |
thanks!!!! |
# |
Jul 5th 2017, 16:39 |
jarard01 |
jeremyharris, it was a sort condition I had on the query that was causing the issue |
# |
Jul 5th 2017, 16:39 |
jeremyharris |
what is files.0.file_id? |
# |
Jul 5th 2017, 16:39 |
pedroseco |
it adds the records, as expected, into posts_files table. |
# |
Jul 5th 2017, 16:38 |
pedroseco |
ok so this is the snippet im using to save Files into Posts when both are with a association belongsToMany: https://gist.github.com/pedroseco/7f960a7399c0ce4aca3dc68051d7fdfa |
# |
Jul 5th 2017, 16:38 |
jeremyharris |
I’m getting a little confused cause the way you’re saving. what’s the end goal here? just save new files and link them to posts, no? |
# |
Jul 5th 2017, 16:37 |
pedroseco |
so probably it’s not correct yet |
# |
Jul 5th 2017, 16:36 |
pedroseco |
and just manipulated the $this->request->data to contain the _joinData |
# |
Jul 5th 2017, 16:36 |
pedroseco |
hum yes but in the last test i ended up not using the newEntity() |
# |
Jul 5th 2017, 16:35 |
jeremyharris |
also, check the saveStrategy |
# |
Jul 5th 2017, 16:35 |
jeremyharris |
if the record already exists, include the id explicitly, and then it won’t just insert new ones |
# |
Jul 5th 2017, 16:34 |
pedroseco |
since altough it creates the records on the join table, it also creates empty records on the foreign model… arghhh |
# |
Jul 5th 2017, 16:34 |
pedroseco |
so probaly i can’t just add the arrays as _joinData |
# |
Jul 5th 2017, 16:34 |
pedroseco |
eheh |
# |
Jul 5th 2017, 16:33 |
jeremyharris |
@savant we need a :rubberduck: emoji :P |
# |
Jul 5th 2017, 16:33 |
pedroseco |
2many hours around the same problem gets this kind of result :| |
# |
Jul 5th 2017, 16:33 |
jeremyharris |
np :slightly_smiling_face: sometimes extra pair of eyes/ears are helpful. :rubberduck: |
# |
Jul 5th 2017, 16:32 |
pedroseco |
arghh. sorry @jeremyharris. You are right, the code you helped me with, before, by some reason is now creating empty records on Files table and then associating those… |
# |
Jul 5th 2017, 16:30 |
pedroseco |
let me see if by some reason the code I did on the save before is creating empty entries. |
# |
Jul 5th 2017, 16:30 |
jeremyharris |
what happens if you do $this->Files->get(‘eec8af26-c4e7-463d-ad60-3712b1f9dd90’) |
# |
Jul 5th 2017, 16:29 |
jeremyharris |
and you’re certain that those IDs have data in them? they’re not remnants of previous tests? |
# |
Jul 5th 2017, 16:28 |
pedroseco |
all null but they are not null on the database and only show like this if from a contain find |
# |
Jul 5th 2017, 16:28 |
pedroseco |
check in the files array. |
# |
Jul 5th 2017, 16:28 |
pedroseco |
@jeremyharris ok so this is the json result of the Post find with Contain Files https://gist.github.com/pedroseco/b36a3d76c0a66e37af8b8986f1cee017 |
# |
Jul 5th 2017, 16:26 |
jeremyharris |
check the sql log, it may just always be using ORDER Properties.id ASC every time. if so, remove the ->order from your query to allow the paginator to do the sorting |
# |
Jul 5th 2017, 16:25 |
jeremyharris |
oh wait it looks like you already have an ->order clause. I don’t remember if it removes that, perhaps remove that |
# |
Jul 5th 2017, 16:24 |
jeremyharris |
did you first try removing the whitelist entirely? |
# |
Jul 5th 2017, 16:23 |
jarard01 |
it still won't sort - I don't get it |
# |
Jul 5th 2017, 16:22 |
jeremyharris |
I’m not following. can you gist the whole find() along with the result array? |
# |
Jul 5th 2017, 16:21 |
pedroseco |
(they are filled on the database.) |
# |
Jul 5th 2017, 16:21 |
pedroseco |
yup it returns null fields only id / created / modified on Files are !empty. |
# |
Jul 5th 2017, 16:20 |
jeremyharris |
maybe I’m not understanding :slightly_smiling_face: |
# |
Jul 5th 2017, 16:20 |
jeremyharris |
@pedroseco and that result doesn’t contain all the post data? |
# |
Jul 5th 2017, 16:20 |
jeremyharris |
jarard01 if you want to allow anything to be used for sorting (except contains) then you don’t need the whitelist |
# |
Jul 5th 2017, 16:20 |
pedroseco |
its a simple $this->Posts->find()->where(xxx)->contain([Files]). were you talking about the result? |
# |
Jul 5th 2017, 16:20 |
jarard01 |
I also read the whiteListing is only required for virtual fields and related models? |
# |
Jul 5th 2017, 16:19 |
jarard01 |
jeremyharris, I just edited controller and view to both only use the field name, it still doesn't work |