OSDN Git Service

fix orm
[pettanr/pettanr.git] / lib / manifest / model / association / has_many.rb
1 module Manifest
2   module ModelModule
3     module AssociationModule
4       class HasMany
5         attr :association, :has_many_name, :has_many_manifest, 
6           :model_name, :foreign_key, :through
7         def initialize association, has_many_name, has_many_manifest
8           @association = association
9           @has_many_name = has_many_name
10           @has_many_manifest = has_many_manifest
11           self.set_default
12           self.init
13         end
14         
15         def set_default
16           @has_many_manifest['model_name'] ||= @has_many_name.singularize
17           @has_many_manifest['foreign_key'] ||= @association.model_name + '_id'
18         end
19         
20         def init
21           @model_name = @has_many_manifest['model_name']
22           @foreign_key = @has_many_manifest['foreign_key']
23           @through = @has_many_manifest['through']
24         end
25         
26         def model
27           ::Manifest.item_name_to_model @model_name
28         end
29         
30         def association_name
31           @association.association_name
32         end
33         
34       end
35       
36     end
37   end
38 end