uploadMany without Mjoin

uploadMany without Mjoin

maxmediamaxmedia Posts: 14Questions: 7Answers: 0

I am trying to implement uploadMany without using recommended link table and Mjoin class. The reason is that I have several separate uploadMany fields in main table. This would require separate link table for each field I guess.

I have tried this approach: https://datatables.net/forums/discussion/61382/is-it-possible-to-use-uploadmany-without-join#latest
This approach uses get/set formatter to implode/explode array of id's into string stored in main table field. At first look it seems to work.

But i have came into the same trouble: I can upload, save record but not edit, because "files" in json server response doesn't contain all files needed, only the first one.
I have found that reason for this is how db() method works. It takes raw value of editor field as stored in database (string) without formatters and uses this value in IN clause to return info about files stored in that field. The query looks like this:

SELECT id .... FROM files WHERE id IN "1|2|3"

SQL tries to convert "1|2|3" to integer, which is 1, so this query returns only the first file.
Any ideas? @yokowasis how did you solve this?
Tested on Editor 2.4.1

Answers

  • allanallan Posts: 65,082Questions: 1Answers: 10,775 Site admin

    Hi,

    As you've found, there are paths in the server-side code that would require modification for this to work I'm afraid. They are (as I recall) optimisations so it is possible that if someone had this working before, it was with an old version.

    I'm trying to think if it would be possible to use a single link table - would that be suitable for your needs if so? It would probably need to have a condition applied to an extra column to indicate which field it belongs to.

    Allan

  • maxmediamaxmedia Posts: 14Questions: 7Answers: 0

    Hi Allan,
    thanks for reply. Having extra column in link table would probably solve my issue. I was wondering if that isn't already possible with Mjoin class, but probably not.

    But that inspired me doing this on files table instead: having extra column set in db() method to some static value (different for each field) and then using where() method of Upload class. Of course, this requires that one file is used only for one field, but that's ok. What you think?

    I need to test it, but at the same time I am struggling with deleting files from uploadMany field: all files can be deleted just fine but the last one. Leaving field empty doesn't send that field to server on update at all. So server doesn't set it to null. I have checked in debug console, the uploadMany field is not in UPDATE clause.
    But maybe using link as proposed will resolve this bug as well.

Sign In or Register to comment.