From 3f52ba6e319555a4d6e80262dd356e1984b330fb Mon Sep 17 00:00:00 2001 From: Christoph Olszowka Date: Mon, 4 Nov 2024 11:13:59 +0100 Subject: [PATCH] Update nested_models.md with workaround notes as per #187 --- docs/nested_models.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/nested_models.md b/docs/nested_models.md index 458b204..16acf05 100644 --- a/docs/nested_models.md +++ b/docs/nested_models.md @@ -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 < 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.