mysql - Duplicating SQL Row in Ruby -
a basic function can't head around.
i need copy values 1 mysql row new row - sounds easy.
i've tried below, setting key_tasks equal cloned future_tasks instead of expected result of creating new rows each task, keeps same id, , doesn't create new row. @performance_review relates current review taking place , appraisals[-2] relates 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
found solution. seems 'dup' doesn't work on collections.
appraisals[-2].performance_review.future_tasks.each |t| t['future'] = 0 @performance_review.key_tasks << t.dup end
Comments
Post a Comment