Sha256: 46364b92b39e311c8194e042696783717505921e0aaf1f97d419cfacd57647c8
Contents?: true
Size: 762 Bytes
Versions: 3
Compression:
Stored size: 762 Bytes
Contents
module ApiResource module Associations class HasOneRemoteObjectProxy < SingleObjectProxy def initialize(klass, owner) super(klass, owner) # now if we have an owner and a foreign key, we set the data up to load self.remote_path = self.klass.collection_path(self.owner.class.to_s.foreign_key => self.owner.id) end protected # because of how this works we use a multi object proxy and return the first element def to_condition ApiResource::Conditions::MultiObjectAssociationCondition.new(self.klass, self.remote_path) end def load(opts = {}) res = Array.wrap(self.to_condition.load).first @loaded = true res end end end end
Version data entries
3 entries across 3 versions & 1 rubygems