I'm using Filestore to make uploads in a form. It's a great implementation but I've a doubt about associating that file uploaded with a register in a table.
When I run the filestore.001.sql, it add 4 tables in Database (filestore_image, filestore_file, filestore_volume, filestore_extension).
Then in anoter table I have:
id
field1
idfile
I was thinking in how to do that association when I submit the form. Maybe a dsql() and then selectin开发者_高级运维g the last inserted file, but I don't know if this is the best option.
Thanks Alejandro
When you add a image field to a form, it will return you ID (or list of uploaded file id's) on submission. So theoretically user can upload image and never submit form, hence it wouldn't be associated.
You can have the following table:
- id
- name
- picture_id
and define picture as type image, there should be examples on the site - it will automatically receive ID from the filestore_file table.
There is another way you can do and it's exactly how Filestore_Image is being built. You can make your own model, and link it with necessary image and use that for your image field. Since it's your model, you can now control what happens before inserting, you can override beforeInsert and afterInsert events to build the proper associations.
Both methods have their own uses, pick the one which you like.
精彩评论