# Inventory Project

**URL:** <https://www.ruby-forum.com/t/inventory-project/82061>\
**Category:** Rails\
**Created:** [March 15, 2006, 3:38am UTC](https://www.ruby-forum.com/t/inventory-project/82061 "2006-03-15T03:38:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahul\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/43a26b/32.png) [@rahul\_m](https://www.ruby-forum.com/u/rahul_m)\
**Post date:** [March 15, 2006, 3:38am UTC](https://www.ruby-forum.com/t/inventory-project/82061/1 "2006-03-15T03:38:11Z")

</div>

I am trying to write a inventory web application with RoR so that I can  
keep track of hardware and software purchased by the company. I would  
also like to be able to associate products we buy with users and  
departments. I would like it if you could enter in products (since we  
purchase many of the same) into a product list.  
Then you could add a user or department and check off which products he  
has and then maybe some AJAX for cool effects for entering the serial  
numbers or additional information. I am not sure if it is the best way  
but I wanted to add a new column to the “users” table everytime a  
product was entered and then that would be available to select. I would  
like to know how I would have to have this project designed so that it  
can work within the MVC framework and what tables you think I might  
need.

~Rahul

---

<div class="post-metadata">

**Author:** ![rahul\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/43a26b/32.png) [@rahul\_m](https://www.ruby-forum.com/u/rahul_m)\
**Post date:** [March 15, 2006, 4:30am UTC](https://www.ruby-forum.com/t/inventory-project/82061/2 "2006-03-15T04:30:03Z")

</div>

Hi Rahul,

> From your description I don’t think that adding a column to the user table  
> would be wise. This would limit the number of products that you could  
> add  
> to what ever the database can handle as the number of fields.

Rather if I have understood you correctly you could use a table  
structure  
like:

Products  
id  
name  
user\_id  
department\_id  
…

Users  
id  
…

Departments  
id  
…

Then your classes could be something along the lines of

Product  
belongs\_to :user  
belongs\_to :department

User  
has\_many :products

Department  
has\_many :products

You could then add products into a list, and associate them with either  
a  
department, a user or both.

Cheers

---

<div class="post-metadata">

**Author:** ![rahul\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/43a26b/32.png) [@rahul\_m](https://www.ruby-forum.com/u/rahul_m)\
**Post date:** [March 15, 2006, 4:48am UTC](https://www.ruby-forum.com/t/inventory-project/82061/3 "2006-03-15T04:48:26Z")

</div>

On Tue, 2006-03-14 at 20:37 -0600, Rahul M. wrote:

> like to know how I would have to have this project designed so that it  
> can work within the MVC framework and what tables you think I might need.
> 
> ~Rahul

Adding columns is not just a bad idea … it is an evil idea that will  
make the product unusable in the long term.

You will need at least these tables:  
ITEMS: list of available items and generic sorts of information about  
them  
ITEM\_ATTRIBUTES: name -\> value attribute pairs for each item  
USERS: list of users known to the system  
USER\_ATTRIBUTES: name -\> value attribute pairs for each user  
DEPARTMENTS: list of departments known to the system  
INVENTORY: list of all instances of inventory items and where to find  
them (user, department, installed in machine, etc)  
INVENTORY\_ATTRIBUTES: name -\> value attribute pairs for each specific  
instance of a product

If you want to track inventory history, which is required in some cases,  
you may need to be a bit creative around the INVENTORY table.

Use the name-attribute pairs unless you find that you are always keying  
in the same type of information - serial number for example. Rows  
(data) can be maintained by the users, but columns (metadata) require a  
programmer’s continual input.

Use surrogate keys (means something to the DBMS, but has no business  
meaning) for robustness and long term maintainability.

I hope this helps.
