For some background, please see my question: Rails app using STI -- easiest way to pull these records?
I have some models joined with a has_many through relationship using a third join table (Recipe and Ingredient joined through RecItem).
So the guys on the prior question helped me to group my recipe's ingredients by type - this is exactly what I wanted. However, now that I am accessing @recipe.ingredients instead of @recipe.rec_items, I can't get back to the data stored in the rec_items join table (stuff like amount of ingredient, how long to cook it, etc...)
Prior to using the group_by, I was iterating through each recipe's rec_items like so:
<% @recipe.rec_items.each do |rec_item| %>
<%= rec_item.ingredient.name %><br />
<%= rec_item.amount %><br />
<% end -%>
Now that I am grouping @recipe.ingredients, how can I follow back to the rec_items related to this recipe? (If I do ingredient.rec_items it gives me rec_items for all recipes...again, I can do this with clunky statements like:
ingredient.rec_items.find_by_recipe_id(@recipe.id).amount
but that seems wrong...) Is there an easy way to accomplish these goals? (getting a list of a particular recipe's ingredients, sorted/grouped by :type, while still being able to access the additional info in rec_items for each recipe/ingredient pairing?)
Thanks!