Rails - seeding data with has_many through association?
===

I have a seed file with the following code within it:

    300.times do
      # create the customer
      customer = Customer.create([
        {customer_type_id: '1'}
      ])
  
      # create an address for the customer
      address = Address.create([
        {city: Faker::Address.city, country: 'UK'}
      ])
      postcode = Postcode.create([
        {value: Faker::Address.uk_postcode}
      ])
      name_number = NameNumber.create([
        {value: Random.rand(495)}
      ])
      street = Street.create([
        {value: Faker::Address.street_name + " " + Faker::Address.street_suffix}
      ])
      state = State.create([
        {value: Faker::Address.uk_county}
      ])

This works fine. I had hoped, however, to be able to do the following:

    address = Address.create([
      {city: Faker::Address.city, country: 'UK'}
    ])
    address.postcode = Postcode.create([
      {value: Faker::Address.uk_postcode}
    ])

Where I have created the address in the first line, and I am creating the postcode for the address in the second line. This, however, generates an error.

Could anyone suggest how I can do this?

Thanks!