title: How do I update a child db table when populating database in ruby on ralls?
body: <p>I have the following tables in my database:</p>
  
  <ul>
  <li>User(s) - has one profile, has many PhotoAlbums</li>
  <li>Profile(s) - belongs to user</li>
  <li>PhotoAlbum(s) - belongs to user, has many photos</li>
  <li>Photo(s) - belongs to PhotoAlbum</li>
  </ul>
  
  <p>Faker works fine when it comes to populating my users table but I now wish to update my profiles table also but it doesn't work at all. The rows in the db still remain empty. I have no errors showing up when I run rake db:populate.</p>
  
  <p>Am I missing something, please help me see where I'm going wrong and help me come up with a solution as this will help me when I need to populate my other tables too. What I learn from this answer can help me with other tasks I have coming up.</p>
  
  <p>libs/task/sample_data.rake</p>
  
  <pre><code>   namespace :db do
          desc "Create user records in the development database."
          task :populate =&gt; :environment do
            require 'faker'
  
  
            def randomDate(params={})
              years_back = params[:year_range] || 5
              latest_year  = params [:year_latest] || 0
              year = (rand * (years_back)).ceil + (Time.now.year - latest_year - years_back)
              month = (rand * 12).ceil
              day = (rand * 31).ceil
              series = [date = Time.local(year, month, day)]
              if params[:series]
                params[:series].each do |some_time_after|
                  series &lt;&lt; series.last + (rand * some_time_after).ceil
                end
                return series
              end
              date
            end
  
            def decimal_selection_array(start,limit,step_size=1)
              decimal_array = (start..limit).step(step_size).map{|i| i.to_s}.to_a
              decimal_array.insert(0,"Below #{start.to_f}")
              decimal_array.insert(-1,"Above #{limit.to_f}")
            end
  
            100.times do |n|
              username = "#{Faker::Name.first_name}#{n}"
              u = User.create!(
                :username =&gt; username,
                :email =&gt; Faker::Internet.email,
                :password =&gt; "foobar"
              )
  
  
              u.profile.update_attributes(
            :motd                =&gt; Faker::Lorem.words,
  
            #Profile details
            :first_name          =&gt; Faker::Name.first_name,
            :last_name           =&gt; Faker::Name.last_name,
            :birthday            =&gt; randomDate(:year_range =&gt; 60, :year_latest =&gt; 22),     
            :gender              =&gt; (1..2).to_a.sample,
            :marital_status      =&gt; (1..7).to_a.sample,
            :sexual_preference   =&gt; (1..3).to_a.sample,
            :ethnicity           =&gt; (1..10).to_a.sample,
            :country             =&gt; Faker::Address.country,
            :location            =&gt; Faker::Address.country,
  
            #About the user
            :about_me            =&gt; Faker::Lorem.paragraph,
  
            #Personal stats
            :height              =&gt; decimal_selection_array(5.0,7.0,0.1).to_a.sample,
            :body_type           =&gt; (1..7).to_a.sample,
            :eye_colour          =&gt; (1..6).to_a.sample,
            :drugs               =&gt; (1..4).to_a.sample,
            :alcohol             =&gt; (1..4).to_a.sample,
            :cigarettes          =&gt; (1..3).to_a.sample,
            :likes               =&gt; Faker::Lorem.sentence,
            :dislikes            =&gt; Faker::Lorem.sentence,
            :bad_habits          =&gt; Faker::Lorem.sentence,
  
            #Favourite things
            :food                =&gt; Faker::Lorem.sentence,
            :music               =&gt; Faker::Lorem.sentence,
            :television          =&gt; Faker::Lorem.sentence,
            :book                =&gt; Faker::Lorem.sentence,
            :animal              =&gt; Faker::Lorem.sentence,
            :place               =&gt; Faker::Lorem.sentence,
            :possesion           =&gt; Faker::Lorem.sentence
  
  
              )
  
  
  
  
  
          end
        end
      end
  </code></pre>
  
  <p>Kind regards</p>