Bogdan Popa
Bogdan Popa

Reputation: 1099

Find all with conditions

I have 3 models. LimitType, LimitGroup and LimitGroupValue.

class LimitGroupValue < ActiveRecord::Base

  belongs_to :limit_group
  belongs_to :limit_type

end

I have the limit_group object (has many limit_group_values) and I want to find all limit_group_values which belong to a limit_type with a certain attribute value(code to be 'wager min').

I tried with:

@group.limit_group_values.find(:all, conditions: { limit_type: {code: 'WAGER_MIN'}})

@group.limit_group_values.find(:all, conditions: "limit_type.code = 'WAGER_MIN'")

I can't really seem to find a way. What am I doing wrong?

P.S. :Using rails 2.

Upvotes: 1

Views: 71

Answers (1)

Vishnu Atrai
Vishnu Atrai

Reputation: 2368

Try below -

@group.limit_group_values.find(:all, :joins => :limit_type , :conditions => [ "limit_type.code = ?", 'WAGER_MIN']).to_a

Upvotes: 1

Related Questions