Sha256: 767bd0705d73cf793f3066bcb657f2b8cfa9c0495dd1467f4b47001a58f09057
Contents?: true
Size: 783 Bytes
Versions: 2
Compression:
Stored size: 783 Bytes
Contents
--- id: implicit_cloner title: Implicit Cloner --- When [cloning associations](include_association.md) Clowne tries to infer an appropriate cloner class for the records (unless `clone_with` specified). It relies on the naming convention: `MyModel` -> `MyModelCloner`. Consider an example: ```ruby class User < ActiveRecord::Base has_one :profile end class UserCloner < Clowne::Cloner include_association :profile end class ProfileCloner < Clowne::Cloner finalize do |source, record| record.name = "Clone of #{source.name}" end end user = User.last user.profile.name #=> "Bimbo" cloned = UserCloner.call(user).to_record cloned.profile.name # => "Clone of Bimbo" ``` **NOTE:** when using [in-model cloner](active_record.md) for ActiveRecord it is used by default.
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
clowne-1.1.0 | docs/implicit_cloner.md |
clowne-1.0.0 | docs/implicit_cloner.md |