./lib/plugins/db_helpers/link_plugin.rb in lux-fw-0.1.17 vs ./lib/plugins/db_helpers/link_plugin.rb in lux-fw-0.1.35
- old
+ new
@@ -17,11 +17,11 @@
# link :genders, default:1, collection:[ [1, 'male'], [2, 'Female'] ]
# link :genders, collection: { 1=>'male', 2=>'Female' }
# Object.genders
# @object.gender
- def link(name, opts={})
+ def link name, opts={}
name_s = name.to_s.singularize
name_p = name.to_s.pluralize
if opts[:collection]
field = opts[:field] || "#{name_s}_id"
@@ -62,10 +62,10 @@
# cities -> [<City:1>, <City:2>, <City:4>]
elsif new.respond_to?("#{name_s}_ids")
# puts "* #{to_s}.link :#{name} -> inline #{name_s}_ids".yellow
class_eval %[
def #{name_p}
- return [] if #{name_s}_ids.blank?
+ return if #{name_s}_ids.blank?
ids = #{name_s}_ids.join(',')
#{klass}.where(Sequel.lit('id in ('+ids+')'))
end
]