0

I have an array that keeps some instances of a model (SupplierPhone) like this:

supplier_phone = SupplierPhone.where(:supplier_id => 1)
supplier_phone =  [#<SupplierPhone id: 1, supplier_id: 1, phone: "22423434234",
created_at: "2011-07-21 00:56:26", updated_at: "2011-07-21 00:56:26">, 
#<SupplierPhone id: 2, supplier_id: 1, phone: "98776234423", 
 created_at: "2011-07-21 00:56:27", updated_at: "2011-07-21 00:56:27">] 

I want to save each element of the array supplier_phone in a new instance of SupplierPhone, can somebody tell me how can I do this?

Thanks in advance!

2 Answers 2

1
supplier_phone.each{ |sp| SuplierPhone.create(sp.attributes) }
Sign up to request clarification or add additional context in comments.

Comments

0

you can use associations. supplier has_many :phones", then get the phones through a chain "supplier.phones"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.