Class: Schemaker::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.
17 18 19 20 |
# File 'lib/schemaker/models/subject_model.rb', line 17 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
12 13 14 |
# File 'lib/schemaker/models/subject_model.rb', line 12 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)
31 32 33 34 |
# File 'lib/schemaker/models/subject_model.rb', line 31 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
23 24 25 |
# File 'lib/schemaker/models/subject_model.rb', line 23 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!
37 38 39 |
# File 'lib/schemaker/models/subject_model.rb', line 37 def = {} .merge super(:object).merge(foreign_key_option :subject) end |