Module: ActiveTsv::Reflection
- Included in:
- Base
- Defined in:
- lib/active_tsv/reflection.rb
Instance Method Summary collapse
Instance Method Details
#belongs_to(name) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/active_tsv/reflection.rb', line 33 def belongs_to(name) class_eval " def \#{name}\n \#{name.to_s.classify}.where(self.class.primary_key => self[\"\#{name}_id\"]).first\n end\n CODE\nend\n", __FILE__, __LINE__ + 1 |
#has_many(name, through: nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/active_tsv/reflection.rb', line 3 def has_many(name, through: nil) if through class_eval " def \#{name}\n \#{name.to_s.classify}.where(\n \#{name.to_s.classify}.primary_key => \#{through}.pluck(:\#{name.to_s.singularize.underscore}_id)\n )\n end\n CODE\n else\n class_eval <<-CODE, __FILE__, __LINE__ + 1\n def \#{name}\n \#{name.to_s.singularize.classify}.where(\n \#{self.name.underscore}_id: self[self.class.primary_key]\n )\n end\n CODE\n end\nend\n", __FILE__, __LINE__ + 1 |
#has_one(name) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/active_tsv/reflection.rb', line 23 def has_one(name) class_eval " def \#{name}\n \#{name.to_s.singularize.classify}.where(\n \#{self.name.underscore}_id: self[self.class.primary_key]\n ).first\n end\n CODE\nend\n", __FILE__, __LINE__ + 1 |