summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6de5aed)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
has_many :coitems
has_many :bitems
has_many :coitems
has_many :bitems
+ has_many_polymorphs :purchaseables, :from => [:coitems, :bitems], :through => :purchases
+
validates_presence_of :name, :email, :phone, :address
validates_numericality_of :debt
validates_presence_of :name, :email, :phone, :address
validates_numericality_of :debt
--- /dev/null
+class Purchase < ActiveRecord::Base
+ belongs_to :customer
+ belongs_to :purchaseable, :polymorphic => true
+end
--- /dev/null
+class CreatePurchases < ActiveRecord::Migration
+ def self.up
+ create_table :purchases do |t|
+ t.column :customer_id, :integer
+ t.column :purchaseable_id, :integer
+ t.column :purchaseable_type, :string
+ end
+ end
+
+ def self.down
+ drop_table :purchases
+ end
+end
# migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
# migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
-ActiveRecord::Schema.define(:version => 15) do
+ActiveRecord::Schema.define(:version => 16) do
create_table "bitems", :force => true do |t|
t.column "customer_id", :integer, :null => false
create_table "bitems", :force => true do |t|
t.column "customer_id", :integer, :null => false
t.column "price", :decimal, :precision => 8, :scale => 2, :default => 0.0
end
t.column "price", :decimal, :precision => 8, :scale => 2, :default => 0.0
end
+ create_table "purchases", :force => true do |t|
+ t.column "customer_id", :integer
+ t.column "purchaseable_id", :integer
+ t.column "purchaseable_type", :string
+ end
+
create_table "rentables", :force => true do |t|
t.column "type", :string
t.column "title", :string
create_table "rentables", :force => true do |t|
t.column "type", :string
t.column "title", :string
--- /dev/null
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+two:
+ id: 2
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+
+class PurchaseTest < Test::Unit::TestCase
+ fixtures :purchases
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end