I found a strange behavior in Rails 4 with scopes when I use postgres. I have a Object with saleStartDate and saleEndDate attributes. scope :active, -> { where(isActivate: true) }> scope :activeDate, -> { active.where("? BETWEEN saleStartDate AND > saleEndDate", Date.today)}When I use sqlite, all works when I want to get the object with the activeDate scope. When I use postgres, I get an error "pg:error salestartdate column not found"! Postgres is case sensitive! So why does Rails convert saleStartDate to salestartdate in a scope? I changed saleStartDate to sale_start_date. Now it works. Is it best practice to use _ and not CamelCase in scopes? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/162db918-b0f9-4765-bd4a-96eb4bcf5ec9%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Sep 15, 2013, at 5:48 AM, Nicolas Mauchle <nmauchle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Postgres is case sensitive! So why does Rails convert saleStartDate to salestartdate in a scope?You misunderstand postgres. It implements the case insensitivity required by SQL standards via a bit of a kludge--downcasing all identifiers that are not quoted. I''d bet this would have worked: scope :activeDate, -> { active.where(''? BETWEEN "saleStartDate" AND "saleEndDate"'', Date.today)}> Is it best practice to use _ and not CamelCase in scopes?Well, I don''t know that I want to say "best practice" because I *like* using mixed case in my schemas, and I have a lot of legacy tables that way, but with postgres in particular is sure as heck would be *easier* to use all lower case ;-) -- Scott Ribe scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org http://www.elevated-dev.com/ (303) 722-0567 voice -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6DC5320D-44B8-4974-BE45-06D852B12EA8%40elevated-dev.com. For more options, visit https://groups.google.com/groups/opt_out.
Possibly Parallel Threads
- string downcase or how to use downcase an hostname in puppet?
- BUG in actionpack , error evaluating nil.downcase ?
- Getting AR to downcase table and column names
- Help with error "undefined method `downcase' for nil:NilClass" after migration
- Downcasing Legacy Table Column Names