muscat icon indicating copy to clipboard operation
muscat copied to clipboard

Upgrade to Rails 7.1: remove composed_of

Open xhero opened this issue 1 year ago • 0 comments

Currently, the marc class is mapped to the models in a clever way using composed_of:

composed_of :marc, :class_name => "MarcSource", :mapping => [%w(marc_source to_marc), %w(record_type record_type)]

Unfortunately in rails 7.1 composed_of freezes the object, and since Muscat makes the assumption that Marc objects are modifiable, it crashes. See https://github.com/rails/rails/pull/46377

This means that to be compatible with 7.1 we need to remove composed_of. Since (fortunately) the serialisation of the marc obj is done in set_object_fields, we can just add the code to read and de serialise marc from the db:

  def marc
    @marc ||= MarcSource.new(self.marc_source, self.record_type)
  end

  def marc=(marc)
    self.marc_source = marc.to_marc
    self.record_type = marc.record_type
    
    @marc = marc
  end

And it should do the trick. This needs to be teste throughly to see if there are hidden caveats...

xhero avatar Dec 19 '23 08:12 xhero