Method: ActiveTsv::Reflection#has_many

Defined in:
lib/active_tsv/reflection.rb

#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