I have two tables. They are Service Desk and Incident. I have to relate one of my service desk records with one or more service desk record(s) and/or one or more incident record(s). Hence the result of my search will both service desk records and/or incident records. MY PROBLEM IS WHAT SHOULD BE THE TABLE STRUCTURE TO STORE THIS RESULT INCLUDING THE TYPE OF IT(ie WHETHER IT IS SERVICE DESK OR INCIDENT RECORD) Thanks 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 -~----------~----~----~----~------~----~------~--~---
One, you can do just as you say and "include the type". Create a ''type'' column in each table with either an integer or you can place a string of "Service Desk" or "Incident" Also what i would do is, I am positive you have a record or ticket number or something like that. I would place a ''SD'' or ''IN'' in front of the number to so you can tell what kind of record it is. If you have the same columns in each table then you can combine all the records in one table and just have a Ticket or Record table. For example - SD1234 or IN4567 Hope this helps.... JB On Feb 28, 6:00 am, Sijo Kg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have two tables. They are Service Desk and Incident. > > I have to relate one of my service desk records with one or more > service > desk record(s) and/or one or more incident record(s). Hence the result > of > my search will both service desk records and/or incident records. > > MY PROBLEM IS WHAT SHOULD BE THE TABLE STRUCTURE TO STORE THIS RESULT > INCLUDING THE TYPE OF IT(ie WHETHER IT IS SERVICE DESK OR INCIDENT > RECORD) > > Thanks > Sijo > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Use a polymorphic association. It''s polymorphic in the sense that it can associate to any other object in the system. You accomplish this by adding a compound foreign key -- one column gives the name of the class and the other gives the id of the instance. Your models would look something like this: class ServiceDesk has_many :serviceables, :polymorphic=>true belongs_to :service_desk, :as=>:serviceable ... end class Incident belongs_to :service_desk, :as=>:serviceable ... end With that... @service_desk = ServiceDesk.find(1) @service_desk.serviceables <= a collection of ServiceDesk and Incident objects (actually a proxy...) Your migration probably looks like this: def self.up add_column :service_desks, :serviceable_type, :string add_column :service_desks, :serviceable_id, :integer end On Feb 28, 7:00 am, Sijo Kg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have two tables. They are Service Desk and Incident. > > I have to relate one of my service desk records with one or more > service > desk record(s) and/or one or more incident record(s). Hence the result > of > my search will both service desk records and/or incident records. > > MY PROBLEM IS WHAT SHOULD BE THE TABLE STRUCTURE TO STORE THIS RESULT > INCLUDING THE TYPE OF IT(ie WHETHER IT IS SERVICE DESK OR INCIDENT > RECORD) > > Thanks > Sijo > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Hi Thanks for your reply 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 -~----------~----~----~----~------~----~------~--~---
Can u Please evaluate the following as a solution public def get_related_record_model "ServiceDesk" end in the SericeDesk and public def get_related_record_model "Incident" end in Incident model Then to store my result a table service_desk_related_records ============================ id service_desk_ticket_id integer related_record_id integer related_record_model string #To get this I call get_related_record_model related_record_association_type_id | integer created..What do u think of this way? 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 -~----------~----~----~----~------~----~------~--~---
That''s essentially what the polymorphic does for you, with the bonus that "rails magic" takes care of all the coding for you. You only have to change "related_record_model" to "related_record_type" and your work is done. By the way, you don''t need a method to render out the name of the class. Use class.name On Feb 28, 11:47 pm, Sijo Kg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Can u Please evaluate the following as a solution > > public > def get_related_record_model > "ServiceDesk" > end > > in the SericeDesk and > > public > def get_related_record_model > "Incident" > end > > in Incident model > > Then to store my result a table > service_desk_related_records > ============================> id > service_desk_ticket_id integer > related_record_id integer > related_record_model string #To get this I call > get_related_record_model > related_record_association_type_id | integer > > created..What do u think of this way? > > Sijo > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---