forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise a descriptive error from
store_accessor
if the column is not …
…a Store If a developer has neglected to use a structured column type (hstore or json) or to declare a serializer with `ActiveRecord.store`: ```ruby class User < ActiveRecord::Base store_accessor :settings, :notifications end ``` then a `ConfigurationError` will now be raised by `store_accessor` with a descriptive error message: ActiveRecord::ConfigurationError: the column 'settings' has not been configured as a store. Please make sure the column is declared serializable via 'ActiveRecord.store' or, if your database supports it, use a structured column type like hstore or json. Previously, in this situation, a `NoMethodError` was raised when the accessor was read or written: ```ruby puts user.notifications ``` Raising an exception earlier, with a helpful message, should help developers understand more quickly what's wrong and how to fix it. Note that this change makes `store_accessor` call `type_for_attribute` which will potentially load the model's schema where it was not being loaded before. As a result, some small changes were needed to the test suite where the `json_data_type` table was not created early enough, and where an anonymous class needed to be bound to a real table. I don't think this should affect the majority of Store users. Closes rails#51699
- Loading branch information
1 parent
43e4916
commit aeedd35
Showing
4 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters