Class: Schemaker::JoinModel

Inherits:
BaseModel show all
Defined in:
lib/schemaker/models/join_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) ⇒ JoinModel

Returns a new instance of JoinModel.

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!



13
14
15
# File 'lib/schemaker/models/join_model.rb', line 13

def initialize models, clazz
  super
end

Instance Method Details

#configureObject

Note:

Do not call super here!

Example:

UsersRoles
  belongs_to :user, :class_name => 'UserAccount' (subject)             
  belongs_to :role, :class_name => 'Role' (object)


35
36
37
38
# File 'lib/schemaker/models/join_model.rb', line 35

def configure          
  create_belongs_to :subject, class_name_option(:subject)
  create_belongs_to :object, class_name_option(:object)
end

#simple_keyObject



17
18
19
# File 'lib/schemaker/models/join_model.rb', line 17

def simple_key
  clazz_name.to_s.underscore
end

#through_keyObject



21
22
23
# File 'lib/schemaker/models/join_model.rb', line 21

def through_key
  make_key clazz_name
end