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

Update nested_models.md with workaround notes as per #187 #190

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/nested_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,22 @@ If you want to validate the nested model, you must use the `StoreModelValidator`
attribute :supplier, Supplier.to_type # existing attribute definition
validates :supplier, store_model: true
```

### Work-around for loading database schema in Rails 7.2+

In Rails 7.2+, a [private attribute registration callback has been removed and at time of writing, no replacement is available](https://github.com/rails/rails/issues/52685).

Due to this, when using `store_model` with `accepts_nested_attributes_for` the database schema is required to be available in your database before booting your application. This will
occur for example when setting up a new environment or in CI.

The only known workaround for this currently is to load the database structure before you run your application, i.e. using psql. Please note that even `rails dbconsole` is affected
by this and hence you have to prepare your database without touching any of your rails application whatsoever. You must also use the `sql` structure dump, as loading `schema.rb` requires
to boot your application, which you won't be able to.

```bash
psql <auth flags and database name> < db/structure.sql
bundle exec rails console
```

See also [this issue](https://github.com/DmitryTsepelev/store_model/issues/187) for further discussion. Please also consider [contributing the necessary API to Rails](https://github.com/rails/rails/issues/52685#issuecomment-2310728692)
so there can be a less clunky solution to this.
Loading