Sijo Kg
2008-Sep-26 06:28 UTC
Iterating through each record of a model and copy that to an
Hi
I have to copy all the service desk cis to incident cis as part of
converting sd_ticket to incident..So in the Incident model I did
sd_ticket=ServiceDeskTicket.find(sd_id)
Then a new incident @incident is created here
sd_cis=sd_ticket.get_sd_cis #here I got all the service desk cis
(Relation is ServiceDeskTicket has_many ServiceDeskCis
@incident.incident_cis.add_incident_cis(sd_cis) unless sd_cis.size == 0
#here what I am trying is to add all the sd_cis to incident_cis table
So in IncidentCi class
def self.add_incident_cis(cis_array)
cis_array.each do |ci|
#puts ''In Incidentci cis are : ''+ci.ci_id.to_s
self.incident_id=self.id
self.ci_id=ci.ci_id
#then tries to save record
end
end
This gives me exception And this error I expected since the usage of
self
Exception in Incident is undefined method `incident_id='' for
IncidentCi:Class
What I was trying to do the array iterates in that each sd ci
information is there and get the required ones and copy that to
corresponding incident cis and save
But is there any other way to do this.Please help
service_desk_cis table has the structure
id integer | not null default
nextval(''service_desk_cis_id_seq''::regclass)
service_desk_ticket_id | integer
ci_id | integer |
service_desk_ci_association_type_id | integer |
modified_by | integer |
created_on | timestamp without time zone | not
null
created_at | timestamp without time zone | not
null
updated_on | timestamp without time zone | not
null
updated_at | timestamp without time zone | not
null
incident_cis table has the structure
id integer | not null default
nextval(''incident_cis_id_seq''::regclass)
incident_id | integer |
ci_id | integer |
incident_ci_association_type_id | integer |
modified_by | integer |
created_on | timestamp without time zone | not null
created_at | timestamp without time zone | not null
updated_on | timestamp without time zone | not null
updated_at | timestamp without time zone | not null
Thanks in advance
Sijo
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-26 07:49 UTC
Re: Iterating through each record of a model and copy that to an
On Sep 26, 7:28 am, Sijo Kg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi > I have to copy all the service desk cis to incident cis as part of > converting sd_ticket to incident..So in the Incident model I did > sd_ticket=ServiceDeskTicket.find(sd_id) > Then a new incident @incident is created here > sd_cis=sd_ticket.get_sd_cis #here I got all the service desk cis > (Relation is ServiceDeskTicket has_many ServiceDeskCis > @incident.incident_cis.add_incident_cis(sd_cis) unless sd_cis.size == 0 > #here what I am trying is to add all the sd_cis to incident_cis table > > So in IncidentCi class > def self.add_incident_cis(cis_array) > cis_array.each do |ci| > #puts ''In Incidentci cis are : ''+ci.ci_id.to_s > self.incident_id=self.id > self.ci_id=ci.ci_id > #then tries to save record > end > endYou should be creating a new instance of IncidentCi and setting values on that (and the values should be coming from ci). self shouldn''t be used in that way at all in this method - it''s just nonsensical. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---