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

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -