Class: Schemaker::Models::SubjectModel
- Defined in:
- lib/schemaker/models/subject_model.rb
Instance Attribute Summary collapse
-
#main_field ⇒ Object
the main field for the behavior to add, fx :troles for adding roles behavior.
Attributes inherited from BaseModel
Instance Method Summary collapse
-
#configure ⇒ Object
Example: UserAccount (subject) has_many :user_roles, :class_name => ‘UserRole’ (join) has_many :roles, :class_name => ‘Role’, :through => :users_roles (subject).
-
#initialize(models, clazz, main_field) ⇒ SubjectModel
constructor
A new instance of SubjectModel.
-
#quick_join(options = {}) ⇒ Object
Used to set up a ‘quick join’ using Rails conventions and ‘has_and_belongs_to_many’ on the subject and object.
- #through_options(options = {}) ⇒ Object
Methods inherited from BaseModel
Constructor Details
#initialize(models, clazz, main_field) ⇒ SubjectModel
Returns a new instance of SubjectModel.
18 19 20 21 |
# File 'lib/schemaker/models/subject_model.rb', line 18 def initialize models, clazz, main_field super models, clazz @main_field = main_field end |
Instance Attribute Details
#main_field ⇒ Object
the main field for the behavior to add, fx :troles for adding roles behavior
13 14 15 |
# File 'lib/schemaker/models/subject_model.rb', line 13 def main_field @main_field end |
Instance Method Details
#configure ⇒ Object
Example:
UserAccount (subject)
has_many :user_roles, :class_name => 'UserRole' (join)
has_many :roles, :class_name => 'Role', :through => :users_roles (subject)
32 33 34 35 |
# File 'lib/schemaker/models/subject_model.rb', line 32 def configure super create_has_many_through :object, :key => main_field end |
#quick_join(options = {}) ⇒ Object
Used to set up a ‘quick join’ using Rails conventions and ‘has_and_belongs_to_many’ on the subject and object
24 25 26 |
# File 'lib/schemaker/models/subject_model.rb', line 24 def quick_join = {} create_has_and_belongs_to_many :object end |
#through_options(options = {}) ⇒ Object
Note:
important to use super to avoid recursive stack overflow!
38 39 40 |
# File 'lib/schemaker/models/subject_model.rb', line 38 def = {} .merge super(:object).merge(foreign_key_option :subject) end |