Search code examples
ruby-on-railsruby-on-rails-2

Update existing records relation


I have a User resource with like 100 existing user records.

Each user has a relation with a Status table.

user.rb

has_one :status

status.rb

belongs_to :user

I need to create this association not only for new users, but also for existing ones.

How can I do that? Also.. I'm using rails 2.


Solution

  • just use console.

    User.all.each |user|
      Status.create(user_id: user.id)
    end