vendredi 7 avril 2017

Duplicating SQL Row in Ruby

A basic function that I just can't get my head around.

I need to copy the values from one MySQL row to a new row - sounds easy.

I've tried the below, setting key_tasks equal to the cloned future_tasks but instead of the expected result of creating new rows for each task, it keeps the same ID, and thus doesn't create a new row. @performance_review relates to the current review taking place and appraisals[-2] relates to the last completed review.

    @performance_review.key_tasks = appraisals[-2].performance_review.future_tasks.clone
    @performance_review.save

Example row:

539 | test1 | 1 | 130 | 2017-04-07 10:27:42 | 2017-04-07 11:02:10

Expected after clone:

539 | test1 | 1 | 130 | 2017-04-07 10:27:42 | 2017-04-07 11:02:10
540 | test1 | 1 | 131 | 2017-04-07 10:27:42 | 2017-04-07 11:02:10

Actual after clone:

539 | test1 | 1 | 131 | 2017-04-07 10:27:42 | 2017-04-07 11:02:10

Aucun commentaire:

Enregistrer un commentaire