From: Ira W. Snyder Date: Wed, 21 Nov 2007 21:53:03 +0000 (-0800) Subject: Fix object relational modeling X-Git-Tag: turned-in~83 X-Git-Url: https://irasnyder.com/gitweb/?a=commitdiff_plain;h=be6d865110840adfc90f572a4cf14f62bc4cf31e;hp=da20d3ab8101f4f53d2bcd5ed36c5f9ba684f6ee;p=cs356-p2-videostore.git Fix object relational modeling Signed-off-by: Ira W. Snyder --- diff --git a/app/models/coitem.rb b/app/models/coitem.rb index e77f573..a6bc1ad 100644 --- a/app/models/coitem.rb +++ b/app/models/coitem.rb @@ -1,6 +1,6 @@ class Coitem < ActiveRecord::Base - has_one :customer - has_one :rentable + belongs_to :customer + belongs_to :rentable validates_presence_of :customer_id validates_presence_of :rentable_id diff --git a/app/models/customer.rb b/app/models/customer.rb index 11411bb..1a86679 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,5 +1,5 @@ class Customer < ActiveRecord::Base - belongs_to :coitem # FIXME: I hunch this is wrong + has_many :coitem validates_presence_of :name, :email, :phone, :address validates_numericality_of :debt diff --git a/app/models/rentable.rb b/app/models/rentable.rb index faef2c5..5beddc4 100644 --- a/app/models/rentable.rb +++ b/app/models/rentable.rb @@ -1,5 +1,5 @@ class Rentable < ActiveRecord::Base - belongs_to :coitem # FIXME: I hunch this is wrong + has_many :coitem validates_presence_of :title validates_presence_of :genre diff --git a/app/views/coitem/list.rhtml b/app/views/coitem/list.rhtml index 44b9c2d..e506366 100644 --- a/app/views/coitem/list.rhtml +++ b/app/views/coitem/list.rhtml @@ -11,8 +11,8 @@ <% for coitem in @coitems %> - <%=h Customer.find(coitem.customer_id).name %> - <%=h Rentable.find(coitem.rentable_id).title %> + <%=h coitem.customer.name %> + <%=h coitem.rentable.title %> <% for column in Coitem.content_columns %> <%=h coitem.send(column.name) %> <% end %> diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 833c532..3f744c7 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ