def to_mysql_belongs_to(name, options = {})
      field "#{name}_id", type: Integer
      object_class = options[:class] || name.to_s.titleize.delete(' ').constantize
      self.instance_eval do
        define_method(name) do |reload = false|
          if reload
            self.instance_variable_set("@#{name}", nil)
          end

          if self.instance_variable_get("@#{name}").blank? 
            self.instance_variable_set("@#{name}", object_class.where(object_class.primary_key => self.send("#{name}_id")).first)
          end

          self.instance_variable_get("@#{name}")
        end

        define_method("#{name}=(new_instance)") do
          self.send("#{name}_id=", new_instance.id)
          self.instance_variable_set("@#{name}", nil)
        end
      end
    end
def to_mysql_belongs_to(name, options = {})
      field "#{name}_id", type: Integer
      object_class = options[:class] || name.to_s.titleize.delete(' ').constantize
      self.instance_eval do
        define_method(name) do |reload = false|
          if reload
            self.instance_variable_set("@#{name}", nil)
          end

          if self.instance_variable_get("@#{name}").blank? 
            self.instance_variable_set("@#{name}", object_class.where(object_class.primary_key => self.send("#{name}_id")).first)
          end

          self.instance_variable_get("@#{name}")
        end

        define_method("#{name}=(new_instance)") do
          self.send("#{name}_id=", new_instance.id)
          self.instance_variable_set("@#{name}", nil)
        end
      end
    end
Connection methods from mongoid to mysql