Class: Schemaker::Models::JoinModel

Inherits:
BaseModel
  • Object
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!



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

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)


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

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

#simple_keyObject



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

def simple_key
  clazz_name.to_s.underscore
end

#through_keyObject



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

def through_key
  make_key clazz_name
end