Module SeedFu::ActiveRecordExtension
In: lib/seed-fu/active_record_extension.rb

Methods

seed   seed_once  

Public Instance methods

Load some seed data. There are two ways to do this.

Verbose syntax


This will seed a single record. The `:id` parameter ensures that if a record already exists in the database with the same id, then it will be updated with the name and age, rather than created from scratch.

    Person.seed(:id) do |s|
      s.id   = 1
      s.name = "Jon"
      s.age  = 21
    end

Note that `:id` is the default attribute used to identify a seed, so it need not be specified.

Terse syntax


This is a more succinct way to load multiple records. Note that both `:x` and `:y` are being used to identify a seed here.

    Point.seed(:x, :y,
      { :x => 3, :y => 10, :name => "Home" },
      { :x => 5, :y => 9,  :name => "Office" }
    )

Has the same syntax as {seed}, but if a record already exists with the same values for constraining attributes, it will not be updated.

@example

  Person.seed(:id, :id => 1, :name => "Jon") # => Record created
  Person.seed(:id, :id => 1, :name => "Bob") # => Name changed
  Person.seed_once(:id, :id => 1, :name => "Harry") # => Name *not* changed

[Validate]