Sha256: 929b4e41983099a4aef38a8b3ed67b444ec3b9a45bbef001bfaa35a91dedd181
Contents?: true
Size: 527 Bytes
Versions: 1
Compression:
Stored size: 527 Bytes
Contents
module Rollerskates module Associable def belongs_to(table) parent_model = table.to_s.camelize.constantize define_method(table) do parent_model.find_by(id: send("#{table}_id")) end end def has_many(table) child_model = table.to_s.camelize.constantize child_table = table.to_s.pluralize parent_model = model_name.to_s.downcase define_method(child_table) do column = "#{parent_model}_id" child_model.where(column => id) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rollerskates-0.1.1 | lib/rollerskates/orm/associable.rb |