All Questions
9 questions
0
votes
1
answer
181
views
Get properties from all children in a recursive SQL structure
In our product, Company is a model that can have many Companies belonging to it; so some Companies are parents, some are children, and many are both.
We have a ...
3
votes
0
answers
126
views
Custom MySQL duplicate_key update queries
The goal is to create an activity or update its counter if it's already present. And to be super accurate, the code avoids race conditions with a custom ...
2
votes
1
answer
129
views
Building query for search engine
I'm writing a basic search engine for my website.
It works but I'm really unhappy with the code. I know it can't be improved but I'm lacking some experiences here.
In my params from my search I get:
...
14
votes
2
answers
779
views
Nokogiri crawler
The following code works but is a mess. But being totally new to Ruby I have had big problems trying to refactor it into something resembling clean OOP code. Could you help with this and explain what ...
7
votes
1
answer
2k
views
ActiveRecord extension to find next / previous record(s) in one query
I just wrote this gem order_query to find next or previous records relative to the record assuming a (possibly complex) ORDER BY over the records. For example, this ...
5
votes
2
answers
1k
views
How to properly call an "upsert" using parameterized raw SQL to Postgresql in ActiveRecord?
I need to call an upsert to my Category table in PostgreSQL. My current solution uses the exec_query API in ActiveRecord, using ...
1
vote
1
answer
215
views
ActiveRecord SQL search with a filter based on parameters
For work, my colleague and I sketched this method up as a brain dump of how we want this method to work. What I am trying to figure out is how can we break this method into smaller components so that ...
1
vote
1
answer
133
views
Duplicate SQL code in controller
How I can rewrite or refactor my controller code? I have the same SQL query (@plan_gp_users) in all defs.
...
8
votes
1
answer
869
views
Avoiding sub-queries in named scopes
I use named scopes all over the place.
When I have a named scope that deals with two different tables, I tend to query the second table in a sub-query. That way, if I mix and match with other tables ...