11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/erp_work_effort/extensions/active_record/acts_as_routable.rb', line 11
def acts_as_routable
extend ActsAsRoutable::SingletonMethods
include ActsAsRoutable::InstanceMethods
inheriting_class_name = self.name
TransportationRoute.class_exec do
has_many inheriting_class_name.tableize.to_sym,
:through => :associated_transportation_routes,
:source => inheriting_class_name.tableize.singularize.to_sym,
:conditions => ["associated_transportation_routes.associated_record_type = ?", inheriting_class_name],
:dependent => :destroy
@associated_models << inheriting_class_name.tableize
end
AssociatedTransportationRoute.class_exec do
belongs_to inheriting_class_name.tableize.singularize.to_sym,
:class_name => inheriting_class_name,
:foreign_key => "associated_record_id"
end
has_many :associated_transportation_routes, :as => "associated_record", :dependent => :destroy
has_many :routes, :through => :associated_transportation_routes, :source => :transportation_route, :dependent => :destroy
end
|