Thanks Jeremy. One more question if you don't mind. Is there a convenient way to get scalar values from the database? I often do select count or select somefunc() and get a single result.
On Sun, Sep 24, 2017 at 5:08 AM, Jeremy Evans <[email protected]> wrote: > On Saturday, September 23, 2017 at 9:03:05 AM UTC-7, Tim Uckun wrote: >> >> Is there a way to find a model by SQL? I am having a very hard time >> trying to translate this into a Model finder. >> > > Model.with_sql(sql).all > > >> >> select u.* >> from users u left join password_hashes ph on u.id = ph.user_id >> where u.email = ? and >> ph.hashed_password = crypt( ? , ph.hashed_password)' >> >> I tried starting by doing this User.join(:password_hashes, :id, :user_id) >> > > User.select_all(:users). > left_join(:password_hashes, user_id: :id). > where{users[:email] =~ ?}. > where{password_hashes[:hashed_password] =~ crypt(?, > password_hashes[:hashed_password])} > > >> >> But I get a cryptic error >> >> TypeError: no implicit conversion of Symbol into Integer >> from >> /Users/tim/.gem/ruby/2.4.1/gems/sequel-5.0.0/lib/sequel/dataset/query.rb:537:in >> `[]' >> >> BTW is there a way to get the full SQL when errors are being reported. I >> get truncated SQLs which are missing important imformation. >> > > The exception message depends on the driver used. You can try the > error_sql extension and see if it gives you the information you want. > > Thanks, > Jeremy > > -- > You received this message because you are subscribed to the Google Groups > "sequel-talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sequel-talk. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
