开发者

named_scope and substings

开发者 https://www.devze.com 2022-12-27 17:37 出处:网络
I h开发者_JAVA百科ave a named_scope in rails that finds episodes by there directors given name named_scope :director_given, lambda { |dr| {:joins => :director, :conditions => [\'given = ?\', dr

I h开发者_JAVA百科ave a named_scope in rails that finds episodes by there directors given name

  named_scope :director_given, lambda { |dr| {:joins => :director, :conditions => ['given = ?', dr]} }

It works great but I would like it to also work on substrings one the name. e.g. instead of having to search for 'Lucy' you could just search 'Lu'.

P.S. I also have another named scope which does exactly the same thing but on the directors last name. It there a way to combine the two?

Thanks,


Something like

named_scope :director_given, lambda { |dr| {:joins => :director, :conditions => ['given LIKE ?', "%#{dr}%"]} }

Second question:

named_scope :director_given, lambda { |dr| {:joins => :director, :conditions => ['first_name LIKE ? OR second_name LIKE ?', "%#{dr}%", "%#{dr}%"]} }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号