aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorEloy Duran <eloy.de.enige@gmail.com>2009-02-01 14:44:30 +1300
committerMichael Koziarski <michael@koziarski.com>2009-02-01 14:44:30 +1300
commitec8f04584479aff895b0b511a7ba1e9d33f84067 (patch)
tree86d6580345865cd1ce63b2055c0eca091ba8ee52 /activerecord/test/models
parenta02d752ae408b34e048b7b040e28c36074a9119f (diff)
downloadrails-ec8f04584479aff895b0b511a7ba1e9d33f84067.tar.gz
rails-ec8f04584479aff895b0b511a7ba1e9d33f84067.tar.bz2
rails-ec8f04584479aff895b0b511a7ba1e9d33f84067.zip
Add support for nested object forms to ActiveRecord and the helpers in ActionPack
Signed-Off-By: Michael Koziarski <michael@koziarski.com> [#1202 state:committed]
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/bird.rb3
-rw-r--r--activerecord/test/models/parrot.rb2
-rw-r--r--activerecord/test/models/pirate.rb7
-rw-r--r--activerecord/test/models/ship.rb7
-rw-r--r--activerecord/test/models/ship_part.rb5
5 files changed, 24 insertions, 0 deletions
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