user3574603
user3574603

Reputation: 3618

Rails: Given an Active_Relation is it possible to determine the query that generated it?

I have an Active_Relation object issues.

    issues = Issue.joins(:language).where(languages: { name: 'C' })

Without knowing what the originally query was, is there a way to determine the query from the object alone? Specifically, is it possible to determine which conditions were supplied to the WHERE clause?

Something like:

    > issues.where_conditions
    =>  { languages: { name: 'C' } }

Upvotes: 1

Views: 92

Answers (1)

Austio
Austio

Reputation: 6085

You do have a few public methods for this. I normally inspect using to_sql b/c it tells me what will be executed, which is normally what i'm looking to know.

There is also where_values_hash and joined_includes_values

Upvotes: 3

Related Questions