Nice bit to know about calling "my" to get the original context.
I'd started creating variables before the where clause so I could call them, I think "my" is better.
Love Squeel. Love that I don't have to mess with ARel.
I love Ernie Miller's two main projects (Squeel & Ransack / previously metawhere & metasearch).
As much as Squeel cleans up DB look ups, I find Ransack totally brilliant, it makes standard (and you can go quite sophisticated) searches in indexes so easy and flexible!
Ransack is great for simple cases, however imho on more complex scenarios I'd rather write search from scratch, otherwise one ends up with those long names like name_matches_or_translation_name_matches that are somewhat unintuitive, and some even more complex scenarios cannot be expressed at all. So when search requirements bypass a certain threshold one should replace Ransack with a solution from scratch rather than fight it's API.
I'd second this. I wouldn't have written Ransack if there weren't use cases for it, but I do feel some guilt, sometimes, over making it easy for people to do the wrong thing. I'd also note that it's important, for public-facing and high-traffic search forms, to consider an inverted index search of some kind.
I've heard that claim before and it typically means your specs do a large amount of AR object creation on the fly via factories. For some use cases, MetaWhere used to actually increase benchmarked performance.
As for Squeel, I haven't done any such benchmarking, but I'd be interested to see the results.
I got this working great in the rails console, right off the bat. Fell in love immediately. Then when I implemented it in the views I kept getting "wrong number of arguments 0 for 1". Googling around I found I wasn't the only one, lots of people were getting that error and I couldn't really find a strait answer.
Eventually I restarted the rails session and BOOM, it works!
So
"wrong number of arguments 0 for 1" => try restarting session.
anyone have tips on creating a dynamic query with Squeel. for example if i have an array of conditions [[column,operator,value],[column,operator,value]]
How would i iterate over those and dynamically build a query in squeel?
in ultra basic format
ruby
defself.with_conditions(conditions)
where do
conditions.each do |column,operator,value|
(column operator value)
endendend
I just added the squeel gem to the Gemfile in my project, did a bundle install and it installed without a problem. I then tried to use it with a very simple query like this:
InsertionOrder.where{id = 1}
in a controller and got
ArgumentError: wrong number of arguments (0 for 1+)
I tried the same query and many variations in the rails console and still got the same error.
InsertionOrder.where(id: 1) works just fine.
I saw that patrick above says restarting his session helped but it has for me on many restarts.
I've tried using several other operators and tried putting the expression in parentheses, but with no change in result.
I Tried doing the rake initialization to make the squeel.rb config file in case that would help but it didn't.
@milenmaxon ORM = Object Relational Mapping, in plain language, it's a wrapper for connecting to and querying databases that is for the most part, agnostic about the choice of database.
Thanks Ryan.
This is good if all database drivers support it. Otherwise we'll have the same issue as using plain old SQL.
IMHO, unless something like this is adopted by Rails out of the box, the prons and cons of using a gem with another DSL almost even.
Since Squeel converts down to ARel, which underpins pretty much all of ActiveRecord, you shouldn't have any problems related to DB drivers.
Ok, it makes sense.
Thanks.
I have a gist integrating Squeel with CanCan ( https://gist.github.com/1523940 ) that lets one do outer joins and less common operations:
Hope Ryan will integrate it soon.
We use Squeel on all of our projects and it totally rocks. It's a really pretty little DSL.
Nice bit to know about calling "my" to get the original context.
I'd started creating variables before the where clause so I could call them, I think "my" is better.
Love Squeel. Love that I don't have to mess with ARel.
I've used Squeel exclusively for developing my tagging library. Compared to acts as taggable on steriods the code is very readable.
https://github.com/bradphelan/rocket_tag
It makes writing composable SQL a breeze.
I love Ernie Miller's two main projects (Squeel & Ransack / previously metawhere & metasearch).
As much as Squeel cleans up DB look ups, I find Ransack totally brilliant, it makes standard (and you can go quite sophisticated) searches in indexes so easy and flexible!
Ransack is great for simple cases, however imho on more complex scenarios I'd rather write search from scratch, otherwise one ends up with those long names like
name_matches_or_translation_name_matches
that are somewhat unintuitive, and some even more complex scenarios cannot be expressed at all. So when search requirements bypass a certain threshold one should replace Ransack with a solution from scratch rather than fight it's API.I'd second this. I wouldn't have written Ransack if there weren't use cases for it, but I do feel some guilt, sometimes, over making it easy for people to do the wrong thing. I'd also note that it's important, for public-facing and high-traffic search forms, to consider an inverted index search of some kind.
What are the performance concerns with using Squeel?
We recently removed Metawhere from our Rails 3.0.x app and our specs complete around 5X faster.
I've heard that claim before and it typically means your specs do a large amount of AR object creation on the fly via factories. For some use cases, MetaWhere used to actually increase benchmarked performance.
As for Squeel, I haven't done any such benchmarking, but I'd be interested to see the results.
What's about Sequel? README CheatSheet
What is better Squeel or sequel?
They're different creatures. Squeel is a DSL that works with ActiveRecord -- Sequel is an entirely different ORM.
Does Squeel support hstore?
Is there a good way to implement this functionality?
I got this working great in the rails console, right off the bat. Fell in love immediately. Then when I implemented it in the views I kept getting "wrong number of arguments 0 for 1". Googling around I found I wasn't the only one, lots of people were getting that error and I couldn't really find a strait answer.
Eventually I restarted the rails session and BOOM, it works!
So
"wrong number of arguments 0 for 1" => try restarting session.
anyone have tips on creating a dynamic query with Squeel. for example if i have an array of conditions [[column,operator,value],[column,operator,value]]
How would i iterate over those and dynamically build a query in squeel?
in ultra basic format
I just added the squeel gem to the Gemfile in my project, did a bundle install and it installed without a problem. I then tried to use it with a very simple query like this:
InsertionOrder.where{id = 1}
in a controller and got
ArgumentError: wrong number of arguments (0 for 1+)
I tried the same query and many variations in the rails console and still got the same error.
InsertionOrder.where(id: 1) works just fine.
I saw that patrick above says restarting his session helped but it has for me on many restarts.
I've tried using several other operators and tried putting the expression in parentheses, but with no change in result.
I Tried doing the rake initialization to make the squeel.rb config file in case that would help but it didn't.
Any ideas?
@milenmaxon ORM = Object Relational Mapping, in plain language, it's a wrapper for connecting to and querying databases that is for the most part, agnostic about the choice of database.