Questions tagged [finder-sql]

9 questions
6
votes
2 answers

Porting complicated has_many relationships to Rails >4.1 (without finder_sql)

I am porting a Rails app to Rails 4.2. This Rails app contains some rather complex manual SQL code in associations - partly due to DB optimizations (e.g. subselects instead of JOINs), partly due to no feasible alternative at the time of writing…
Jens
  • 1,386
  • 14
  • 31
5
votes
4 answers

How do I pass a string to a has_many :finder_sql parameter?

In my application, a user has_many tickets. Unfortunately, the tickets table does not have a user_id: it has a user_login (it is a legacy database). I am going to change that someday, but for now this change would have too many implications. So…
MiniQuark
  • 46,633
  • 36
  • 147
  • 183
5
votes
1 answer

How to combine different classes from an STI table into a single result set using ActiveRecord?

We're building an application that creates group pages similar to Facebook's group pages. Someone can post to a page and that post can have replies. Since they have very similar properties, the posts and the replies are combined into the same STI…
Peter Nixey
  • 16,187
  • 14
  • 79
  • 133
4
votes
3 answers

finder_sql does not parse string with Rails

I have the problem that the query I use for finder_sql is not parsed correctly before it is handed over to PostgreSQL resulting in a database syntax error. To illustrate the problem I just used the example code from…
3
votes
4 answers

Rails3: how to set default conditions to has_many

I have boxes and balls. Balls are in boxes. Ball can be either red and green. class Box < ActiveRecord::Base has_many :balls end class Ball < ActiveRecord::Base belongs_to :box scope :green, where(:color => "green") end I want to set…
petRUShka
  • 9,812
  • 12
  • 61
  • 95
1
vote
0 answers

Rspec/Rails: writing a test for a has_many with finder_sql condition

Here is my has_many statement: has_many :managed_athletes, class_name: "Athlete", finder_sql: ->(record) do record = self if record.nil? "SELECT DISTINCT users.* FROM users INNER JOIN contributorships …
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189
1
vote
2 answers

Rails find_by_sql - how to run generic queries

I need to execute this query to find out the next auto_increment value that will be used by MySQL for a particular table. find_by_sql ["select auto_increment from information_schema.tables where table_schema = ? and table_name = ? and…
Vijay Dev
  • 26,966
  • 21
  • 76
  • 96
0
votes
1 answer

Can you use association extensions on an object with custom finder_sql?

I was under the impression that the custom_finder option in ActiveRecord meant that you got association extensions like .where and .order for free, for instance: class Dog < ActiveRecord::Base has_many :fleas, class_name: 'Flea', …
Peter Nixey
  • 16,187
  • 14
  • 79
  • 133
-3
votes
1 answer

R 2.15.2 sqlFetch() on Win7 OS is terminating the R session

R 2.15.2 sqlFetch() on Win7 OS is terminating the R session. However, sqlQuery() function returns the values properly with termination. Please, help me resolving the issue.