postgresql - Rails changes postgres SELECT * to SELECT COUNT -


I am working with RailsCast on token input and am trying to clear a query method for Postgres . I got to make my query db-agnostic.

My method:

  def self.tokens (query) t = language.arel_table languages ​​= Language.where (t [: name]. March ("% # {Query}% ")) if in languages [{Id: "<< query}> 
", name: "new: \" # {query} \ ""}] ending

returns

 : 001 & gt;  

But if language from "language" ("language" "name" ILIKE '% RU%'). I use language = instead of return , I get the right query:

txt = .arel_table return language: where (t [: names] matches ("% # {query}%")) <001> Language. ('Ru') language load (0.9 mms) Select "languages". * WHERE ("Languages". "Name" ILIKE '% RU%') from "Languages"

This is probably something obvious, but I did not know why the first method should be chosen Because the 'languages' table is selecting count instead of all the rows in the DB. I would really like to store the result of that query in a variable.

This is because where it has been solved as it might possibly be (unless it's absolutely Not required)

  • Check blank?
  • It's counting, the reason is that in your case it needs:

    1. Through counting it is decided that it is empty is.


    Comments

    Popular posts from this blog

    java - org.apache.http.ProtocolException: Target host is not specified -

    java - Gradle dependencies: compile project by relative path -

    ruby on rails - Object doesn't support #inspect when used with .include -