is it possible to use uploadMany without Join ?

is it possible to use uploadMany without Join ?

yokowasisyokowasis Posts: 12Questions: 3Answers: 0
edited April 7 in Free community support

I can't really make it works. It just keep throwing "Array to string conversion in MysqlQuery.php"

The example is using join table, is it possible to not doing this ?

Answers

  • rf1234rf1234 Posts: 1,444Questions: 50Answers: 195

    I guess you are referring to this example:
    https://editor.datatables.net/examples/advanced/upload-many

    Well, you definitely need the join!

    What you need is:
    - a table holding the references to your files ("file")
    - a table holding the logical entity you are saving files for (e.g. "widget", "contract", "tool" whatever it is ...) - and that is the table you are actually editing!
    - the link table between the two

    Take a look at this thread please:
    https://datatables.net/forums/discussion/comment/164076/

  • yokowasisyokowasis Posts: 12Questions: 3Answers: 0

    Yes, that's what I am referring to.

    I mean it's possible to use single upload without join. Can't we just store the the id of the files separated by comma in the database ?

  • yokowasisyokowasis Posts: 12Questions: 3Answers: 0

    How about this, is there a way to catch the multi uploaded files ids, and submit that instead

  • rf1234rf1234 Posts: 1,444Questions: 50Answers: 195

    Well, you can do anything. But you would need to code it yourself, I guess. Why reinvent something that already exists and works? And it certainly is better data modelling to use the 3 tables as discussed instead of saving a comma separated string with ids ... But that is up to you of course :smiley:

  • allanallan Posts: 51,750Questions: 1Answers: 7,832 Site admin

    To confirm my understanding @yokowasis, you want to allow multiple files to be uploaded for a single field, but just to store the ids for the files in a comma separated string (or something) in the host table, rather than needing to use a link / junction table?

    Personally I would suggest against doing it that way - use a link table with Mjoin, but if you must do it with a comma separated list of ids, you could use the array formatters on the server-side to chop it into an array (getFormatter) and bring the array from the client-side back into a string on set.

    Allan

  • yokowasisyokowasis Posts: 12Questions: 3Answers: 0
    edited April 17

    @allan

    Yes that's what I want. I don't know why the method would be different between single and multiple uploads.

    In single uploads you just need 1 additional table (table files), contain information such as url, server path, etc. And that's all you need. No join needed.

    I tried it your suggestion, but it doesn't work. Any example would be great.

  • allanallan Posts: 51,750Questions: 1Answers: 7,832 Site admin

    Could you show me what you used please?

    Thanks,
    Allan

  • yokowasisyokowasis Posts: 12Questions: 3Answers: 0

    For future user who has the same problem with me, here is the code that works for me

                            $Field
                                ->getFormatter(Format::explode())
                                ->setFormatter(Format::implode())
                                ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/'.$this->uploadfolder.'/__ID__.__EXTN__' )
                                    ->db( 'files', 'id', array(
                                        'filename'    => Upload::DB_FILE_NAME,
                                        'filesize'    => Upload::DB_FILE_SIZE,
                                        'web_path'    => Upload::DB_WEB_PATH,
                                        'system_path' => Upload::DB_SYSTEM_PATH
                                    ) )                        
                                    ->validator( Validate::fileSize( 5000000, 'Maksimal File 5MB' ) )
                                    ->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif', 'pdf', 'docx', 'doc', 'csv', 'xlsx', 'xls' ), "File tidak dikenali" ) )
                                );
    

    Thanks @allan for the help.

    I have no idea why it didn't work before. I delete it, because, well, it didn't work.

  • yokowasisyokowasis Posts: 12Questions: 3Answers: 0
    edited April 20

    Ok, now another problem arise.

    I can save and retrieve, but I can't edit.

    It says

    dataTables.editor.min.js:12 Uncaught Unknown file id 17 in table files
    

    here is the table json

    {
        "data": [{
            "DT_RowId": "row_9",
            "id": "9",
            "checkbox": "",
            "date": "2020-04-17",
            "datetime": "2020-04-20 08:06:08",
            "hidden": "Default Value",
            "password": "asdasdasd",
            "radio": "",
            "readonly": "ReadOnly Value",
            "select": "-",
            "text": "",
            "textarea": "",
            "upload": "1",
            "uploadMany": ["12", "17"],
            "uploadManyID": "3",
            "image": null,
            "currency": "",
            "autocomplete": "",
            "multiselect": "",
            "selectdb": "-",
            "rtf": ""
        }],
        "options": [],
        "files": {
            "files": {
                "1": {
                    "id": "1",
                    "filename": "LOGO diginusa.jpg",
                    "filesize": "1207774",
                    "web_path": "\/bimasoft-wp-mms\/wp-content\/uploads\/1.jpg",
                    "system_path": "\/home\/u0328216\/aplikasi.mtsn1kobi.sch.id\/bimasoft-wp-mms\/wp-content\/uploads\/1.jpg"
                },
                "12": {
                    "id": "12",
                    "filename": "asd.jpg",
                    "filesize": "36280",
                    "web_path": "\/bimasoft-wp-mms\/wp-content\/uploads\/12.jpg",
                    "system_path": "\/Volumes\/Data\/git\/bimasoft-wp-mms\/wp-content\/uploads\/12.jpg"
                }
            }
        }
    }
    

    Probably because there is no id 17 on the files. It seems on upload many, only the first id, is included in the files json.

  • allanallan Posts: 51,750Questions: 1Answers: 7,832 Site admin

    What version of the server-side libraries are you using please? It does appear to work in this example which is using 1.9.2.

    Thanks,
    Allan

Sign In or Register to comment.