All notable changes to this project will be documented in this file.
- Fixed: Make
ActiveType::Object
work on Rails 7.2.
- Passing unfrozen objects as a default for an attribute is deprecated, since these objects might be shared between records.
- Fixed: Calling
#attributes
on the base record after a cast works now and does not throw aMutationAfterCastError
- Added: You can implement an
#after_cast
that is called with the original record when callingActiveType.cast
. Thanks to @MaximilianoGarciaRoe.
- Fixed: ActiveType.cast preserves
.strict_loading?
and.readonly?
- Fixed:
accepts_nested_attributes_for
ignores virtual attributes. Thanks to @nalabjp.
- Fixed: Allowed some more attribute methods on casted objects without causing a UnmutableAttributes error.
- Fixed: Fixed an issue (#168) when
change_association
is called with a scope proc only. Thanks to @foobear.
- Fixed: Fixed an issue when certain keywords are used as attribute names. Thanks to @tom-kuca.
- Fixed: Original Rails #attribute method now aliased as #ar_attribute correctly. Thanks to @sudoremo.
- Fixed: ActiveType::Object#serializable_hash includes virtual attributes.
- Fixed: ActiveType now actually works for Rails 7. Sorry for that. Thanks to @atcruice.
- Fixed: Ruby compiler warning and suboptimal attribut name validation. Thanks to @remofrizsche.
- Fixed: ActiveType now works for Rails 7.
- Added: Casting is prevented when the base record has changes in its already loaded associations, because those would be lost. Option
force: true
can be used to override this and still do the cast (this is not recommended). - Added: After casting, the base record will not be usable any more. The base record and the newly created casted record share state which is unexpected. Option
force: true
can be used to override this, so the base record is still usable (this is not recommended).
- Removed: When casting an unsaved record, the new record will no longer have the same associations as the base record. This was introduced with version 1.8.0 and lead to issues (#147 and #148). Therefore the change was rolled back.
- Removed: Tests for Ruby 2.4 and ActiveRecord 3.2.
- Fixed: Retain
#mutations_from_database
when using ActiveType.cast (Rails 5.2+). Thanks to @unrooty-infinum.
-
Fixed: Extended records now use their own I18n namespace when looking up translations for models or attributes. (introduced in 1.4.0)
There was an issue (#142) when extending an already extended records again. Now the I18n lookup will fall back fall back correctly to the extended record's or even the base record's namespace.
- Added: When casting an unsaved record, the new record will have the same associations as the base record.
- Added: Support for Ruby 3.0.
- Fixed: Numerous issues with Rails 6.1. Thanks to @vr4b4c for some of the changes.
- Added: When serializing/deserializing
ActiveType::Record
orActiveType::Object
with YAML, virtual attributes are restored. Credits to @chriscz.
- Fixed: Assigning values to virtual attributes through internal setter methods (e.g.
_write_attribute
) no longer results in "can't write unknown attribute" errors.
- Fixed: Avoid
Module#parents
deprecation warning on Rails 6. Thanks to @cilim.
-
Extended records now use their own I18n namespace when looking up translations for models or attributes. If the extended record's namespace does not contain a translation, the lookup will fall back to the base record's namespace.
For instance, given the following class hierarchy:
class User < ActiveRecord::Base end class User::Form < ActiveType::Record[User] end
The call
ExtendedParent.human_attribute_name(:foo)
would first look up the key inactiverecord.attributes.user/form
first, then falls back toactiverecord.attributes.user
.Thank you @fsateler!
- Fixed:
nests_one
association record building used empty hash instead of passed in attributes. Credit to @chriscz.
- Fixed: Avoid #change_association breaking for polymorphic associations. Thanks to @lucthev.
-
Fixed: Do not override Rails internal methods when definining an attribute called
:attribute
. -
Fixed: Fix .find for extended records, when a record had a
#type
column that was not used for single table inheritance. Thanks to @fsateler. -
Changed: When extending a single table inheritance base class,
.find
no longer crashes, but returns records derived from the extended class.This means, that given the following class hierarchy:
class Parent < ActiveRecord::Base end class ExtendedParent < ActiveType::Record[Parent] end class Child < Parent end
querying
ExtendedParent.all
will no longer crash, but always return records of type
ExtendedParent
(even if they would normally of typeChild
). You should probably avoid this weird situation and not extend STI Parent classes.Thanks to @fsateler.
- Fixed: Eager loading in Rails 6 no longer crashes trying to load
ActiveType::Object
s. Thanks to @teamhqapp for the fix.
- Fixed: Using
has_many
et al in an extended record ignored given scopes. - Added:
change_association
on ActiveType::Record to change assocation options.
- Improved dirty tracking (
#changes?
etc) for virtual attributes to bring it more in line with the behaviour of non-virtual attributes. Behaviour with ActiveRecord < 4 remains unchanged. Thanks to @lowski.
- For some use cases, users need to access ActiveRecord's original
.attribute
method, which ActiveType overrides. We now alias.attribute
as.ar_attribute
. - In a
ActiveRecord::Record[MyRecord]
,.has_many
now guesses"my_record_id"
as the foreign key. Same for.has_one
.
- No code changes.
- Modernize list of supported Rails versions and Rubies.
- Fixed an
chird record did not match id
exception introduced in the 0.7.3 update when usingnests_one
. Credit to @cerdiogenes.
- Bugfix: ActiveType.cast sets #type correctly when casting to an STI class
nests_many
/nests_one
will now work for nested records with non-integer primary keys.
- Fixed a bug when converting datetimes from certain strings. This occured if the string included an explicit time zone (i.e.
record.date_time = '2017-07-31 12:30+03:00'
), which was not the local time.
- ActiveType::Object no longer requires a database connection on Rails 5+ (it never did on Rails 3 or 4).
- Support
index_errors: true
fornest_many
.
- Fix an issue when using
ActiveType.cast
"too early".
- Fix a load error when using
ActiveType::Object
before usingActiveRecord::Base
within a Rails app.
- When used with Rails, defer loading to not interfere with
ActiveRecord
configuration in initializers.
- Remove spec folder from packaged gem.
- Drop support for 1.8.7.
- Rails 5 compatibility.
- Fix an issue with incorrectly copied errors on Util.cast.
- Nicer
#inspect
method.
- Fixed issue
#dup
ingActiveType::Object
- Call
#after_commit
forActiveType::Object
- Fix issue with Booleans on mysql.
- Add
attribute_will_change!
for virtual attributes.
- Add
attribute_was
for virtual attributes.
- Add ActiveType.cast to cast ActiveRecord instances and relations to extended models
- Make gem crash during loading with ActiveRecord 4.2.0 because #31
- Support belongs_to associations for ActiveRecord 4.2.1
- Ensure that ActiveType::Object correctly validates boolean attributes (issue #34)
- Don't crash for database types without casting rules (fixes #25)
- Making the gem to work with Rails version 4.0.0
- Use native database type for type casting in pg
- Support nested attributes in extended records (fixes #17)
- Add support for Rails 4.2beta