adonisjs / attachment-lite

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

Improvements to `setOptions` calls and `afterFind` hook #25

Closed ndianabasi closed 9 months ago

ndianabasi commented 1 year ago

Proposed changes

This PR fixes two critical issues observed while using this add-on.

  1. The options set with setOptions on runtime are not remembered through the lifecycle of persistence operation. For example: column.setOptions({folder: '123/abc'}) does not always work. After being set on the Attachment class' options object, the new option does not reflect when the decorator carries out persistence of the file.
  2. When this add-on is used together with similar add-on (such as Adonis Responsive Attachment) within the same model, when the model hooks are executed, the attachment instance of other add-ons is passed into this add-on which leads to error as the methods of the other add-on's instance might not be available.

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...

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

RomainLanz commented 1 year ago

Hey @ndianabasi! 👋🏻

It seems we have a typing issue about options being private in the Attachment class, but you set it public in the declaration.

It currently works because the TypeScript private operator is not doing anything at runtime, but a truly private field would make the code break.

Could you please change that and add some tests to ensure your changes work as expected?

ndianabasi commented 12 months ago

Thanks for the response @RomainLanz. I've forked this repo and made all fixes I needed. Also gives me latitude to introduce features I need as well. Thanks for all you do!

stale[bot] commented 9 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.