lib/ymldot.rb in ymldot-0.0.1 vs lib/ymldot.rb in ymldot-0.0.2
- old
+ new
@@ -1,7 +1,8 @@
require 'yaml'
require 'pp'
+require 'util'
class Entity
def initialize(name, dependent, columns = [])
@name = name
@dependent = dependent
@@ -141,30 +142,30 @@
eval_relation_polymorphic(foreignkeys["polymorphic"], tname) if foreignkeys["polymorphic"]
end
def eval_relation_has_many(keys, tname)
keys.each do |rel|
- @entity_dict[rel].foreignkeys << "#{tname}ID(FK)"
+ @entity_dict[rel].foreignkeys << "#{singularize(tname)}ID(FK)"
@many_relations << {:self => @entity_dict[tname], :have => @entity_dict[rel]}
end
end
def eval_relation_has_one(keys, tname)
keys.each do |rel|
- @entity_dict[rel].foreignkeys << "#{tname}ID(FK)"
+ @entity_dict[rel].foreignkeys << "#{singularize(tname)}ID(FK)"
@one_relations << {:self => @entity_dict[tname], :have => @entity_dict[rel]}
end
end
def eval_relation_hmabt(keys, tname)
keys.each do |rel|
join_tname = "#{rel}_#{tname}"
return if @entity_dict.has_key? join_tname
join_tname = "#{tname}_#{rel}"
@entity_dict[join_tname] ||= Entity.new(join_tname, true)
- @entity_dict[join_tname].foreignkeys << "#{tname}ID(FK)"
- @entity_dict[join_tname].foreignkeys << "#{rel}ID(FK)"
+ @entity_dict[join_tname].foreignkeys << "#{singularize(tname)}ID(FK)"
+ @entity_dict[join_tname].foreignkeys << "#{singularize(rel)}ID(FK)"
# make new category
keys = []
keys << "#{tname}ID(FK)"
keys << "#{rel}ID(FK)"
@@ -175,11 +176,11 @@
end
end
def eval_relation_polymorphic(keys, tname)
keys.each do |rel|
- @entity_dict[tname].foreignkeys << "#{rel["name"]}ID(FK)" if key = rel["name"]
- @entity_dict[tname].columns.unshift "#{rel["type"]}(type)" if key = rel["type"]
+ @entity_dict[tname].foreignkeys << "#{singularize(rel["name"])}ID(FK)" if key = rel["name"]
+ @entity_dict[tname].columns.unshift "#{singularize(rel["type"])}(type)" if key = rel["type"]
rel["tables"].each do |t|
@one_relations << {:self => @entity_dict[t], :have => @entity_dict[tname] }
end
end
end