Sha256: 1a760b1a60a1203a31643ba05dd419a65619c306db614c94860aaaed75d5674b

Contents?: true

Size: 799 Bytes

Versions: 3

Compression:

Stored size: 799 Bytes

Contents

require 'syncano/model/associations/base'

module Syncano
  module Model
    module Association
      # Class for belongs to association
      class BelongsTo < Syncano::Model::Association::Base
        attr_reader :associated_model, :foreign_key, :source_model

        # Constructor for belongs_to association
        # @param [Class] source_model
        # @param [Symbol] name
        def initialize(source_model, name, options = {})
          super
          self.foreign_key = options[:foreign_key] || associated_model.name.foreign_key
        end

        # Checks if association is belongs_to type
        # @return [TrueClass]
        def belongs_to?
          true
        end

        private

        attr_writer :associated_model, :foreign_key, :source_model
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
syncano-4.0.0.alpha1 lib/syncano/model/associations/belongs_to.rb
syncano-4.0.0.alpha lib/syncano/model/associations/belongs_to.rb
syncano-4.0.0.pre lib/syncano/model/associations/belongs_to.rb