Ok, thank you very much for these explainations. I've got my answer. Thanks!

Michael Hartl wrote:
> The need for that code was discovered by Insoshi contributor Evan
> Dorn, who found that changes in models (adding validations, for
> example) could break the migration code.  Declaring the model in the
> migration solves this problem, though I admit it's a bit mysterious.
>
> By the way, it's not as easy as bypassing the validations by writing
> something like Forum.new(...).save(false).  In migration 13, which
> adds an admin user, we have code like this:
>
>   class Person < ActiveRecord::Base
>   end
>   .
>   .
>   .
>   def self.up
>     add_column :people, :admin, :boolean, :default => false, :null => false
>     .
>     .
>     .
>     person.admin = true
>
> Without the "class Person < ActiveRecord::Base" part, the
> "person.admin" step fails, because the Person model doesn't have an
> admin column when the migration runs.  Again, for somewhat opaque
> reasons, the model declaration solves the problem.
>
> I've added an explanatory comment to the first occurrence of this code
> (the one you discovered) to allay confusion in the future.
>
> Thanks,
>
> Michael
>
> On Thu, Oct 16, 2008 at 7:10 AM, Thomas Blumenfeld
> <[EMAIL PROTECTED]> wrote:
>   
>> Hi!
>>
>> I was looking into the code of the 005_create_forums.rb migration, it is
>> also present in the last stable release.
>>
>> Here it is:
>> class CreateForums < ActiveRecord::Migration
>>
>>  class Forum < ActiveRecord::Base
>>  end
>>
>>  def self.up
>>    create_table :forums do |t|
>>      t.string :name
>>      t.text :description
>>      t.integer :topics_count, :null => false, :default => 0
>>
>>      t.timestamps
>>    end
>>    Forum.create!(:name => "Discussion forum",
>>                  :description => "The main forum")
>>  end
>>
>>  def self.down
>>    drop_table :forums
>>  end
>> end
>>
>> What does those lines mean?
>>
>>  class Forum < ActiveRecord::Base
>>  end
>>
>> Thx
>>
>> Thomas
>>
>>
>>     
>
>
>
>   


--~--~---------~--~----~------------~-------~--~----~
Insoshi developer site: http://dogfood.insoshi.com/
Insoshi documentation: http://docs.insoshi.com/

You received this message because you are subscribed to the Google
Groups "Insoshi" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/insoshi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to