210geeks/costing — pull request #20 by ryanorsinger (2014-04-11 14:09:48+00:00)
Title: created many-to-many relationships between devices, cpus, rams, hdds, manufacturers, and users

- I renamed RAM, HDD, Manufacturer, and CPU controllers and classes to be plural as per Chris Turner's suggestion. Since he recommends plural table names, he recommends that the controller name matches the plural for ease of reference. Why does he recommend plural table names like cpus instead of cpu? I asked him this and he pointed me to the Laravel Eloquent docs. Eloquent assists us specifically with many-to-many relationships if we have tables that have plural names. See http://laravel.com/docs/eloquent#many-to-many. Eloquent's classes "belongsToMany" and "hasMany" do some "magic" stuff behind the scenes. Here's the details http://laravel.com/api/4.1/Illuminate/Database/Eloquent/Relations/BelongsToMany.html and http://laravel.com/api/4.1/Illuminate/Database/Eloquent/Relations/HasMany.html. These are the behind the scenes classes that generate clean foreign_key names for us.

- in order to set the first part of many to many relationship, I added "public function devices() return $this->belongsToMany('Device');" to our Ram model.

- in order to set the first part of many to many relationship, I added "public function devices() return $this->belongsToMany('Device');" to our Manufacturer model.

- in order to set the first part of many to many relationship, I added "public function devices() return $this->belongsToMany('Device');" to our Hdd model.

- in order to set the first part of many to many relationship, I added "public function devices() return $this->belongsToMany('Device');" to our Cpu model.

- in order to complete the many-to-many relationships in our data model, I added "public function cpus() { return $this->hasMany('Cpu')" to the Device model.

- in order to complete the many-to-many relationships in our data model, I added "public function cpus() { return $this->hasMany('Hdd')" to the Device model.

- in order to complete the many-to-many relationships in our data model, I added "public function cpus() { return $this->hasMany('Manufacturer')" to the Device model.

- in order to complete the many-to-many relationships in our data model, I added "public function cpus() { return $this->hasMany('Ram')" to the Device model.

- in order to complete the many-to-many relationships in our data model, I added "public function cpus() { return $this->hasMany('User')" to the Device model.

- the many-to-many relationship between User and Device exists so that we can properly associate the currently logged in user with the fields "purchased_by" and "refurbished_by" for proper accountability.