how can i get the values using include with conditions in rails? -
i have shop has_many association , include items items belonging shop received
format.json { render json: {:shop => @shops.as_json(:include => :items)}}
now gives items belongs shop want items specific condition, item_type = "accessories". how can this? please me.
edit
i have put new question in how value of include conditions?
you should filter data activerecord, , call as_json on filtered data.
you can like:
@shops = shop.includes(:items).where("items.itemp_type = ?", 'accesories') format.json { render json: { :shop => @shops.as_json(:include => :items) } }
Comments
Post a Comment