Sha256: 736a6a9e7e54795bece8735e4a21da16096c15532c43df4906676cda03fad94f
Contents?: true
Size: 883 Bytes
Versions: 2
Compression:
Stored size: 883 Bytes
Contents
module Sequel class Model ONE_TO_ONE_PROC = "proc {i = @values[:%s]; %s[i] if i}".freeze ID_POSTFIX = "_id".freeze FROM_DATASET = "db[%s]".freeze def self.one_to_one(name, opts) klass = opts[:class] ? opts[:class] : (FROM_DATASET % name.inspect) key = opts[:key] || (name.to_s + ID_POSTFIX) define_method name, &eval(ONE_TO_ONE_PROC % [key, klass]) end ONE_TO_MANY_PROC = "proc {%s.filter(:%s => pkey)}".freeze ONE_TO_MANY_ORDER_PROC = "proc {%s.filter(:%s => pkey).order(%s)}".freeze def self.one_to_many(name, opts) klass = opts[:class] ? opts[:class] : (FROM_DATASET % (opts[:table] || name.inspect)) key = opts[:on] order = opts[:order] define_method name, &eval( (order ? ONE_TO_MANY_ORDER_PROC : ONE_TO_MANY_PROC) % [klass, key, order.inspect] ) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sequel-0.2.1 | lib/sequel/model/relations.rb |
sequel-0.2.1.1 | lib/sequel/model/relations.rb |