11module ActiveRecord
22 module InstanceMethods
33
4+ # if methods are missing, then they must be a column, which we look up
5+ # in the columns_hash.
6+
7+ # For effeciency all attributes will by default have all the methods defined,
8+ # when the class is loaded. See define_attribute_methods class method.
9+ # However a model may override the attribute methods definition, but then call
10+ # super. Which will result in the method missing call.
11+
12+ # When loading data from the server we do NOT want to call overridden methods
13+ # so we also define a _hyperstack_internal_setter_... method for each attribute
14+ # as well as for belongs_to relationships, server_methods, and the special
15+ # type and model_name methods. See the ClassMethods module for details.
16+
417 def method_missing ( missing , *args , &block )
518 column = self . class . columns_hash . detect { |name , *| missing =~ /^#{ name } / }
619 if column
@@ -20,6 +33,16 @@ def method_missing(missing, *args, &block)
2033 # ignore load_from_json when it calls _hyperstack_internal_setter_id
2134 def _hyperstack_internal_setter_id ( *) ; end
2235
36+ # the system assumes that there is "virtual" model_name and type attribute so
37+ # we define the internal setter here. If the user defines some other attributes
38+ # or uses these names no harm is done since the exact same method would have been
39+ # defined by the define_attribute_methods class method anyway.
40+ %i[ model_name type ] . each do |attr |
41+ define_method ( "_hyperstack_internal_setter_#{ attr } " ) do |val |
42+ @backing_record . set_attr_value ( :model_name , val )
43+ end
44+ end
45+
2346 def inspect
2447 "<#{ model_name } :#{ ReactiveRecord ::Operations ::Base ::FORMAT % to_key } " \
2548 "(#{ ReactiveRecord ::Operations ::Base ::FORMAT % object_id } ) " \
0 commit comments