From ec8f04584479aff895b0b511a7ba1e9d33f84067 Mon Sep 17 00:00:00 2001 From: Eloy Duran Date: Sun, 1 Feb 2009 14:44:30 +1300 Subject: Add support for nested object forms to ActiveRecord and the helpers in ActionPack Signed-Off-By: Michael Koziarski [#1202 state:committed] --- activerecord/test/models/bird.rb | 3 +++ activerecord/test/models/parrot.rb | 2 ++ activerecord/test/models/pirate.rb | 7 +++++++ activerecord/test/models/ship.rb | 7 +++++++ activerecord/test/models/ship_part.rb | 5 +++++ 5 files changed, 24 insertions(+) create mode 100644 activerecord/test/models/bird.rb create mode 100644 activerecord/test/models/ship_part.rb (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/bird.rb b/activerecord/test/models/bird.rb new file mode 100644 index 0000000000..341d2eeffc --- /dev/null +++ b/activerecord/test/models/bird.rb @@ -0,0 +1,3 @@ +class Bird < ActiveRecord::Base + validates_presence_of :name +end \ No newline at end of file diff --git a/activerecord/test/models/parrot.rb b/activerecord/test/models/parrot.rb index b9431fd1c0..4a7ed52636 100644 --- a/activerecord/test/models/parrot.rb +++ b/activerecord/test/models/parrot.rb @@ -4,6 +4,8 @@ class Parrot < ActiveRecord::Base has_and_belongs_to_many :treasures has_many :loots, :as => :looter alias_attribute :title, :name + + validates_presence_of :name end class LiveParrot < Parrot diff --git a/activerecord/test/models/pirate.rb b/activerecord/test/models/pirate.rb index 51c8183dee..6a2416a05c 100644 --- a/activerecord/test/models/pirate.rb +++ b/activerecord/test/models/pirate.rb @@ -5,5 +5,12 @@ class Pirate < ActiveRecord::Base has_many :treasure_estimates, :through => :treasures, :source => :price_estimates + # These both have :autosave enabled because accepts_nested_attributes_for is used on them. + has_one :ship + has_many :birds + + accepts_nested_attributes_for :parrots, :birds, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? } + accepts_nested_attributes_for :ship, :allow_destroy => true + validates_presence_of :catchphrase end diff --git a/activerecord/test/models/ship.rb b/activerecord/test/models/ship.rb index 05b09fc1b9..c46e27f3ae 100644 --- a/activerecord/test/models/ship.rb +++ b/activerecord/test/models/ship.rb @@ -1,3 +1,10 @@ class Ship < ActiveRecord::Base self.record_timestamps = false + + belongs_to :pirate + has_many :parts, :class_name => 'ShipPart', :autosave => true + + accepts_nested_attributes_for :pirate, :allow_destroy => true + + validates_presence_of :name end \ No newline at end of file diff --git a/activerecord/test/models/ship_part.rb b/activerecord/test/models/ship_part.rb new file mode 100644 index 0000000000..0a606db239 --- /dev/null +++ b/activerecord/test/models/ship_part.rb @@ -0,0 +1,5 @@ +class ShipPart < ActiveRecord::Base + belongs_to :ship + + validates_presence_of :name +end \ No newline at end of file -- cgit v1.2.3