adonisjs / attachment-lite

Turn any field on your Lucid models to an attachment data type
MIT License
68 stars 20 forks source link

feat: add multiple option to attachment decorator #23

Closed guoyunhe closed 1 year ago

guoyunhe commented 1 year ago

Proposed changes

Sometimes we need to attach multiple files to a model, e.g. a job application may contain CV, cover letter, portfolio, copy of degree certificates, etc.

This PR add an multiple option to the decorator. Like this:

class User extends BaseModel {
  @attachment({ multiple: true })
  public photos: AttachmentContract[]
}

Types of changes

What types of changes does your code introduce?

Put an x in the boxes that apply

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

guoyunhe commented 1 year ago

I am not able to run all the unit tests. Some tests failed with no details. The other tests don't even run...

图片

ndianabasi commented 1 year ago

Hi @guoyunhe.

Thanks for your PR. Did you discuss with Virk if he would like this feature adopted before beginning the PR?

guoyunhe commented 1 year ago

@ndianabasi No.

justDare commented 1 year ago

This is SO damn useful, I hope you get permission + passing tests to get this added.

thetutlage commented 1 year ago

I think multiple attachments should be represented as multiple rows in the database. For example: I will rather have user_photos table and then give user the ability to delete or update each photo as a database row vs storing all photos in a single array.

So, for now I will skip this PR to keep the codebase simple :)