Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model.relation.beforeAdd and model.relation.afterAdd events not called when using AttachOneOrMany::create() #1147

Open
goldmont opened this issue Jun 19, 2024 · 0 comments
Labels
needs review Issues/PRs that require a review from a maintainer

Comments

@goldmont
Copy link

goldmont commented Jun 19, 2024

Winter CMS Build

1.2

PHP Version

8.1

Database engine

MySQL/MariaDB

Plugins installed

No response

Issue description

Hi,

I was trying to debug it and, while reading the sources, I saw this and it doesn't feel right at first glance:
https://github.com/wintercms/storm/blob/374add95da31e6ba1ab4b07ac6d4f03fa85c2503/src/Database/Relations/Concerns/AttachOneOrMany.php#L153-L155

In my controller, I have something like:

$task->attachments()->create(['data' => $attachment])

However, even if attachments are properly attached to my model, model.relation.beforeAdd and model.relation.afterAdd events are not called because $sessionKey is obviously null.

P.s.
From the docs, it reads that is_public property must explicitly set when using the add method. However this condition seems to ensure that the correct value is properly set.

Alternatively, you can prepare a File model before hand, then manually associate the relationship later. Notice the is_public attribute must be set explicitly using this approach.

Any suggestion? Thank you as always.

Steps to replicate

  1. Setup an $attachMany relation.
  2. Attach a file using create method.

Workaround

No response

@goldmont goldmont added needs review Issues/PRs that require a review from a maintainer Type: Unconfirmed Bug labels Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Issues/PRs that require a review from a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants