Not sure if that's what you're trying to achieve but
@awarenesses[0].positionawarenesses.select { |pa| pa.position_id == 12 }.first.level
might do the job.
Paolo
Not sure if that's what you're trying to achieve but
@awarenesses[0].positionawarenesses.select { |pa| pa.position_id == 12 }.first.level
might do the job.
Paolo
Given that positionawarenesses has its own properties, you could also pull this out into its own model. If nothing else, this would create a very efficient query.
class PositionAwareness < ActiveRecord::Base :belongs_to :awareness :belongs_to :position
def self.find_by_position_id_and_awareness_id(position_id, awareness_id) find( :all, :conditions => [ "position_id = ? and awareness_id = ?", position_id, awareness_id ] ) end end
And in your controller: PositionAwareness.find_by_position_id_and_awareness_id(12, @awarenesses[0].id)
Chris