Hi,
I try to import data with a rake-task from a csv-file into a model
like:

provider, which has_many :rates

and

rate, which belong_to: provider

I do the following:

namespace :db do
  desc "load data from csv"
  task :load_csv_data  => :environment do
    require 'fastercsv'

    FasterCSV.foreach("importdata/tarifs.csv",
      :headers => true, :col_sep => ',') do |row|

      Provider.find_or_create_by_name(
        :name => row['Provider_Name'],
        :hotline => row['Hotline'],
        :email => row['Email']
        )

      Rate.find_or_create_by_name(
        :provider => lambda {
                     Provider.find_by_name(row['Provider_Name']) },
        :name => row['Rate_Name'],
        :preis => row['Preis']
        )
    end
  end
end

But the association-key (provider_id) in the table "rates" won't be
writen to the database! I also tried accessing directly provider_id

 :provider_id => lambda
{ Provider.find_by_name(row['Provider_Name']) },

but didn't succeed. Any help is appreciated.

Thanks,
Harm

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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/rubyonrails-talk?hl=en.

Reply via email to