Topic: HABTM Relationship Problem
Hello Everyone, my first post here.
I am getting some very strange behaviour with a habtm relationship.
It is probably eaisiest to explain if i first tell you what this system is designed to do.
Thes system is for my dissertation at university, i am making a system that the user can scan a barcode of a product and see nutritional information and allergies.
For the system the user can scan a barcode, this finds the related product then stores this product firstly in an array of products and secondly in a variable called @lastScanned until it is overwritten. Once the product has been scanned, information is displayed on the screen, the nutritional information is fine. I then loop through the ingredients with the loop below
<% for ingredient in @lastScanned.product.ingredients%>
this has a habtm relationship and works fine. Then inside this loop i try to get all the allergies relating to that ingredient by the loop below
<% for allergy in ingredient.allergies%>
this allso has a link table between called allergies_ingredients and the allergy class and the ingredient class have a habtm relationship. The problem is though, this code updates the database, it sets all records in my link table to only one allergy for each ingredient. Any help with this would be greatly appreciated.
also if someone could tell me how to post code correctly in here i would be very appreciative