-1

Im reading from a external db. So I have made this so the database get created the first time the code runs. I only paste the create part. The reading from the external db is code I not allowed to make public.

Collection.create(
        name:         xxxxxx,
        title:        xxxxxx,
        description:  xxxxx,
        date:         xxxxx,
        collectie:    xxxxx,
        colors:       xxxxxx,
        small_image:  xxxxxx,
    )

How can I change this so the next time only record are updated where data has changed so I do not have to do rake:drop and rake db:migrate and then this rake task if I want to have the latest data.

Edit 1: I tried to change to find_or_create but then I see a lot of errrors

roelof
  • 1
  • 2

1 Answers1

0
item = Collection.where(
    name:         xxxxxx,
    title:        xxxxxx,
    description:  xxxxx,
    date:         xxxxx,
    collectie:    xxxxx,
    colors:       xxxxxx,
    small_image:  xxxxxx
).first_or_create

Then you can manipulate item with item.update if you need to.

  • Thanks, I tried but see then this error message ; https://gist.github.com/rwobben/1f8c375662bdfb13e1cc4655b17b3e43 – roelof May 25 '16 at 11:54
  • Looks like you have a problem with your model. Does the collection match the columns in the database? – Octrillian Jun 01 '16 at 20:35