Class: Schemaker::Models::ObjectModel

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/schemaker/models/object_model.rb

Instance Attribute Summary

Attributes inherited from BaseModel

#logs, #models, #my_class

Instance Method Summary collapse

Methods inherited from BaseModel

#clazz_name, model_types

Constructor Details

#initialize(models, clazz) ⇒ ObjectModel

Returns a new instance of ObjectModel.

Parameters:

  • each (Schema::Models)

    model needs to have access to the collection of models it may need to create relations with

  • reference (Class)

    to the Class it aims to configure!



14
15
16
# File 'lib/schemaker/models/object_model.rb', line 14

def initialize models, clazz
  super
end

Instance Method Details

#configureObject

Configures has_many through relationship via Join model for the object model (fx Role)

Example:

Role (object)
  has_many :accounts,   :class_name => 'RefManyAccount', :through => :accounts_roles (subject)
  has_many :user_roles, :class_name => 'UserRole' (join)


24
25
26
27
# File 'lib/schemaker/models/object_model.rb', line 24

def configure
  super
  create_has_many_through :subject
end

#through_options(options = {}) ⇒ Object

Note:

important to use super to avoid recursive stack overflow!



30
31
32
# File 'lib/schemaker/models/object_model.rb', line 30

def through_options options = {}
  options.merge super(:subject)
end