class Schemaker::Models::SubjectModel
Attributes
main_field[RW]
the main field for the behavior to add, fx :troles for adding roles behavior
Public Class Methods
new(models, clazz, main_field)
click to toggle source
@param [Schema::Models] each model needs to have access to the collection of models it may need to create relations with @param [Class] reference to the Class it aims to configure! @param [Symbol] the name of the main field for the behavior to add, fx :troles for adding roles behavior
Calls superclass method
Schemaker::Models::BaseModel::new
# File lib/schemaker/models/subject_model.rb, line 18 def initialize models, clazz, main_field super models, clazz @main_field = main_field end
Public Instance Methods
configure()
click to toggle source
Example:
UserAccount (subject) has_many :user_roles, :class_name => 'UserRole' (join) has_many :roles, :class_name => 'Role', :through => :users_roles (subject)
Calls superclass method
Schemaker::Models::BaseModel#configure
# File lib/schemaker/models/subject_model.rb, line 32 def configure super create_has_many_through :object, :key => main_field end
quick_join(options = {})
click to toggle source
Used to set up a ‘quick join’ using Rails conventions and ‘has_and_belongs_to_many’ on the subject and object
# File lib/schemaker/models/subject_model.rb, line 24 def quick_join options = {} create_has_and_belongs_to_many :object end
through_options(options = {})
click to toggle source
@note important to use super to avoid recursive stack overflow!
Calls superclass method
Schemaker::Models::BaseModel#through_options
# File lib/schemaker/models/subject_model.rb, line 38 def through_options options = {} options.merge super(:object).merge(foreign_key_option :subject) end