ruby on rails - How To Store Items From a Shopping List -


I am creating an expense tracker

  in the category shopping list_maya: items End class item end  

But I am not sure how to store items, I have yet to consider:

First

  items. New (name: 'milk', value: 1) item New (name: 'chocolate', price 2)  

This would be easy, although the same thing could end up with different names.

  Item.new (name: 'biscuit', value: 3) items. New (name: 'cookies', value: 3)  

second

  class milk and lieutenant; item; And class chocolate & lt; item; Finally the milk. (Value: 1)  

It seems a little complicated, every time you buy something new one class is to be added - on the other hand, once done - I imagine things I'll find it easy to find.

What is the correct way to solve this? What are the related advantages / disadvantages?

The first thing you definitely are at a higher point if you are concerned about the aliases for your name , You can also include in another table

  is the square item_maya: alternate_names end  

and then see the item you save in alternative name table Are you, you have to make, and that relation has to be taken back to the item. So for input name: "biscuit", value: 3 you can do something like

  & gt; Alternatesearch = AlternateName.find_by (name: "biscuit") = & gt; # & Lt; Alternate name ID: 5, item_id: 2, name: "biscuit" & gt; & Gt; Item.find (alternatesearch.item_id) = & gt; # & Lt; Item ID: 2 Name: "Cookies" Price: "3" & gt;  

Or if you can use a new item to search or create alternatesearch and then create a new item, if it makes me feel completely confused that you are in the shopping list What are you doing with or if you want to add new items at all times or want to reuse them, but change the values

I think this is better than the second method because the other way is that the number of objects is very limited and you are basically saving your DB information in RB class files, which It makes it very difficult to change but I think it can be an advantage of how many items you want


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -