簡體   English   中英

使用Dropzone圖像的教義ORM映射中的一對多

[英]OneToMany in Doctrine ORM Mapping with Dropzone images

我在Symfony中有一個表單,其中有一個dropdrop使用dropzone.js上載圖像,當上載圖像時,圖像路徑以及與該表單有關的實體的當前實例的ID都上載到了Image表中分別為imageNamelisting_id listing_id是用戶正在填寫的當前列表的id 由於每個清單都有多個圖像,所以我想知道是否有可能在listing對象和圖像之間保持OneToMany關系。

當用戶單擊“添加列表”時,將使用空值作為草稿(ID除外)創建listing對象,然后將圖像放入其中,以便隨后將其添加到數據庫中。

Listing.php

/**
 * @ORM\OneToMany(targetEntity="Image", mappedBy="listing", cascade={"persist"}, orphanRemoval=true)
 */
private $images;

Image.php

/**
 * @ORM\ManyToOne(targetEntity="Listing", inversedBy="images")
 * @ORM\JoinColumn(name="listing_id", referencedColumnName="id", onDelete="CASCADE")
 */
private $listing;

將圖片放入其中時會導致錯誤,但是如果我將$listing更改為

 /**
 * @ORM\Column(type="integer", nullable=true, name="listing_id")
 */
protected $listing;

它有效,但我的意圖是稍后使用listing對象檢索圖像,因此這不是所需的結果。 我的問題是,即使圖像對象是在與清單不同的時間(后來)創建的,我仍然可以保持這兩個值之間的這種耦合。 照原樣,當我使用這些批注將某些內容放入放置區域時,我會收到錯誤消息。

由於圖像行是實時插入表中的,而不是表單上提交的,因此在使用這種耦合時可能會導致錯誤,但我不確定。

您走在正確的道路上。 我正在為這個任務使用oneup / uploader-bundle。

需要正確的@ManyToOne。 @列將無法正常工作。

但是在我的用例中,它是帶有附加數據的內聯圖像。

我必須停用dropzone自動加載功能,並手動處理dropzone調用和設置,以包括其他表單字段。

還有一個選項是在刪除文件后立即開始手動上傳。 這樣一來,就有可能用一個帖子請求就創建整個東西,而無需事先保留列表就可以擁有一個ID ...

希望對您有所幫助。 我可以共享我的代碼,但現在不能在機器上共享。

編輯:這是我的代碼:

var myDropzone = new Dropzone("#documentTypeUploadDropzone", {

            url : actionUrl,
            dictDefaultMessage: 'Bitte das neue Dokument hier ablegen!',

            // The configuration we've talked about above
            autoProcessQueue: false,

            maxFiles: 1,
            init: function () {
                this.on('success', function(e, serverResponse) {

                    myDropzone.removeAllFiles();

                });

                this.on('sending', function(file, xhr, formData) {
                    // Add additional data form original <form> which was already checked by html5 client side verification
                    formData.append('productId', 1);
                    formData.append('documentType[name]', value1;
                    formData.append('documentType[foreignUrl]',   $(#formInput).val());

                });

                var myDropzone = this;

                $('#documentTypeUploadForm').on('submit', function(e) {
                    // Make sure that the form isn't actually being sent.
                    e.preventDefault();
                    e.stopPropagation();


                    var files = myDropzone.getQueuedFiles();
                    if (!files.length) {
                        $.growl.error({ title:"Fehler", message: 'Bitte zuerst ein Dokument zum Hochladen auswählen.'});
                        return
                    }


                    myDropzone.processQueue();
                });


            }
        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM