Fix object relational modeling
authorIra W. Snyder <devel@irasnyder.com>
Wed, 21 Nov 2007 21:53:03 +0000 (13:53 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Wed, 21 Nov 2007 21:53:03 +0000 (13:53 -0800)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/models/coitem.rb
app/models/customer.rb
app/models/rentable.rb
app/views/coitem/list.rhtml
db/development.sqlite3

index e77f573..a6bc1ad 100644 (file)
@@ -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
index 11411bb..1a86679 100644 (file)
@@ -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
index faef2c5..5beddc4 100644 (file)
@@ -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
index 44b9c2d..e506366 100644 (file)
@@ -11,8 +11,8 @@
   
 <% for coitem in @coitems %>
   <tr>
-  <td><%=h Customer.find(coitem.customer_id).name %></td>
-  <td><%=h Rentable.find(coitem.rentable_id).title %></td>
+  <td><%=h coitem.customer.name %></td>
+  <td><%=h coitem.rentable.title %></td>
   <% for column in Coitem.content_columns %>
     <td><%=h coitem.send(column.name) %></td>
   <% end %>
index 833c532..3f744c7 100644 (file)
Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ