From be6d865110840adfc90f572a4cf14f62bc4cf31e Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Wed, 21 Nov 2007 13:53:03 -0800 Subject: [PATCH] Fix object relational modeling Signed-off-by: Ira W. Snyder --- app/models/coitem.rb | 4 ++-- app/models/customer.rb | 2 +- app/models/rentable.rb | 2 +- app/views/coitem/list.rhtml | 4 ++-- db/development.sqlite3 | Bin 5120 -> 5120 bytes 5 files changed, 6 insertions(+), 6 deletions(-) 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 833c5326679edd286ac36f8b3d940fbc921212cf..3f744c79c4b95388732b01cf594ddad9b6288c7c 100644 GIT binary patch delta 188 zcmZqBXwaA-&8WOl<^wwuv)E=q7H(z>8%0G!RmOnSlGGvv=Zw_6l>9vP5{2x%{PKd5 zqLR|0q?Xkae0 zp(ra0gR*2$Vo732eraY-PO5W$ZfZ)U1Pcp;rev5xT7Hp27|@#3l9EKn07_IdPwp1BWRYQIW0>3{EIs+Luq*(Of)+FY -- 2.25.1