Hi I have limited success with rails and am trying very hard to understand the MVC, DRY and RESTful concepts that Rails supports. What I am trying to do is to automate some data manipulation procedures for legacy systems. I have three tables that I need to import into the Rails application. Table 1 Legacy_System_ID1, Agency_Business_Number, Agency_Name belongs to Table 3 belongs to Table 1 Table 2 Legacy_System_ID2, Legacy_System_ID1, Legacy_System_Contact_ID, Agency_Business_Number, Agency_name has many Table 1 Table 3 Agency_Business_Number, Agency_Name. has many Table 1 These files are all in csv format. What I am having trouble with is the concept of primary key ids. Rails does not like primary keys that are not incremental. I know I can set the primary key to Legacy_System_ID1 in Table 1 and set the foreign key to the same ID in Table 2. The pinch is that I need to seperate the contact_ID from the Legacy_System_ID2 of Table 2 into two tables and also add new entries into Table 3, which is essentially a subset of Table 1 to keep track of which Agencies with unique Agency_Business_Numbers are registered. Whats the best way to go about this in Rails? I am experimenting with Instant Rails 2.02 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
So you need a join table that contains: LEGACY_SYSTEM_ID2 | CONTACT_ID : as fields in which the two fields do NOT use the same ID? On Nov 12, 6:10 pm, Auch <philip...-bhJw6GgyJZ9p6SA07Sphdrpzq4S04n8Q@public.gmane.org> wrote:> Hi > > I have limited success with rails and am trying very hard to > understand the MVC, DRY and RESTful concepts that Rails supports. > > What I am trying to do is to automate some data manipulation > procedures for legacy systems. I have three tables that I need to > import into the Rails application. > > Table 1 > Legacy_System_ID1, Agency_Business_Number, Agency_Name > belongs to Table 3 > belongs to Table 1 > > Table 2 > Legacy_System_ID2, Legacy_System_ID1, Legacy_System_Contact_ID, > Agency_Business_Number, Agency_name > has many Table 1 > > Table 3 > Agency_Business_Number, Agency_Name. > has many Table 1 > > These files are all in csv format. What I am having trouble with is > the concept of primary key ids. Rails does not like primary keys that > are not incremental. I know I can set the primary key to > Legacy_System_ID1 in Table 1 and set the foreign key to the same ID in > Table 2. > > The pinch is that I need to seperate the contact_ID from the > Legacy_System_ID2 of Table 2 into two tables and also add new entries > into Table 3, which is essentially a subset of Table 1 to keep track > of which Agencies with unique Agency_Business_Numbers are registered. > > Whats the best way to go about this in Rails? I am experimenting with > Instant Rails 2.02--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Nov 13, 11:10 am, Auch <philip...-bhJw6GgyJZ9p6SA07Sphdrpzq4S04n8Q@public.gmane.org> wrote:> Hi > > I have limited success with rails and am trying very hard to > understand the MVC, DRY and RESTful concepts that Rails supports. > > What I am trying to do is to automate some data manipulation > procedures for legacy systems. I have three tables that I need to > import into the Rails application. > > Table 1 > Legacy_System_ID1, Agency_Business_Number, Agency_Name > belongs to Table 3 > belongs to Table 1 > > Table 2 > Legacy_System_ID2, Legacy_System_ID1, Legacy_System_Contact_ID, > Agency_Business_Number, Agency_name > has many Table 1 > > Table 3 > Agency_Business_Number, Agency_Name. > has many Table 1 > > These files are all in csv format. What I am having trouble with is > the concept of primary key ids. Rails does not like primary keys that > are not incremental. I know I can set the primary key to > Legacy_System_ID1 in Table 1 and set the foreign key to the same ID in > Table 2. > > The pinch is that I need to seperate the contact_ID from the > Legacy_System_ID2 of Table 2 into two tables and also add new entries > into Table 3, which is essentially a subset of Table 1 to keep track > of which Agencies with unique Agency_Business_Numbers are registered. > > Whats the best way to go about this in Rails? I am experimenting with > Instant Rails 2.02I think your model is saying something like System contact (a person) "has many" Agencies in a nutshell right? -- Daniel Bush --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Daniel Thanks for replying so quickly. In a nutshell, yes. An Agency has many People. Essentially the purpose of the project is to perform an interim admin function to sync two systems. Hence there are two sets of Primary keys and two tables. The third table is the output, where it records the Agency business number to ensure that the Agency is registered. Obviously there will be multiple Agency profiles for the two systems with the primary keys for the agencies. Currently this is being done manually. What I want to find out now is how to generate the view to encompass the values from all three tables into one view, when I am using one of the two system generated lists as a list for users to determine if a client has been registered or not. E.g Agency ID 2 is clicked, which is linked to only one Agency Business Number. How do I represent the values for this Agency ID 2 from the other two tables? Obviously some Agency IDs will not have a corresponding Agency Business Number in table 3 as they have not been registered as yet, or in Table 2 for that matter. I am envisaging the use of partials. I worked out how to generate primary and foreign keys. Currently I have some code in my model that does this, but is not the best. Upload Model def self.save FasterCSV.foreach("D:/Rails/MySql/Migration/file.csv) do |row| unless Agency_ID1.exists?(row[0]) agency = Agency.new(:OrganisationName=>row[1],:TPID=>row[3]) do |i| i.Agency_ID1 = (row[0]) end agency.save end unless person.exists?(row[5]) contact = person.new(:ContactFname=>row[6],:ContactLname=>row [7],:ContactPhone=>row[8], :ContactFax=>row[9],:ContactEmail=>row[10]) do |si| i.ContactID = (row[5]) end contact.save end end end It''s meant to be interim code that helps me load primary key values. I also have a search function working with Acts_as_ferret. This is the model code for Agency 2 (list) acts_as_ferret :fields => [:OrganisationName] This is the controller class SearchesController < ApplicationController def index if params[:q] query = params[:q] @Agency2 = Agency_ID2.find_with_ferret query, :page => params [:page], :per_page => 50 end end end This is the view in views/searches <table> <thead> <tr> <td>OrganisationName</td> <td>smartbuy ID</td> <td>Supplier ABN</td> <td>Supplier TPID</td> </tr> </thead> <tbody> <% @sbtradesuppliers.each do |s| %> <tr> <td><%= link_to s.OrganisationName, Agency2_path(s.id) %></td> <td><%= s.Agency Business Number%></td> <td><%= s.Agency ID 2%></td> </tr> <% end %> </tbody> </table> <br> <br> <br> <%= will_paginate @Agency2 %> My last question is, is this restful? Any help would be much appreciated. On Nov 13, 2:48 pm, Daniel Bush <dlb.id...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 13, 11:10 am, Auch <philip...-bhJw6GgyJZ9p6SA07Sphdrpzq4S04n8Q@public.gmane.org> wrote: > > > > > > > Hi > > > I have limited success with rails and am trying very hard to > > understand the MVC, DRY and RESTful concepts that Rails supports. > > > What I am trying to do is to automate some data manipulation > > procedures for legacy systems. I have three tables that I need to > > import into the Rails application. > > > Table 1 > > Legacy_System_ID1, Agency_Business_Number, Agency_Name > > belongs to Table 3 > > belongs to Table 1 > > > Table 2 > > Legacy_System_ID2, Legacy_System_ID1, Legacy_System_Contact_ID, > > Agency_Business_Number, Agency_name > > has many Table 1 > > > Table 3 > > Agency_Business_Number, Agency_Name. > > has many Table 1 > > > These files are all in csv format. What I am having trouble with is > > the concept of primary key ids. Rails does not like primary keys that > > are not incremental. I know I can set the primary key to > > Legacy_System_ID1 in Table 1 and set the foreign key to the same ID in > > Table 2. > > > The pinch is that I need to seperate the contact_ID from the > > Legacy_System_ID2 of Table 2 into two tables and also add new entries > > into Table 3, which is essentially a subset of Table 1 to keep track > > of which Agencies with unique Agency_Business_Numbers are registered. > > > Whats the best way to go about this in Rails? I am experimenting with > > Instant Rails 2.02 > > I think your model is saying something like > System contact (a person) "has many" Agencies > in a nutshell right? > > -- > Daniel Bush- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I can''t grasp the situation but it just seems to me that if you''re migrating old data into a new system going forward, you should probably massage it and get it normalized and put it into the database in one hit. The best swiss army knives I know of are spreadsheets (and all their functions) and databases (sql and large data sets) for sorting this sort of stuff out. Rails isn''t necessarily the best way to do it although it might help in some situations. Surely table 3 and table 1 should be combined, shouldn''t they? You don''t want 2 tables of agencies. You just want one and you can tell which are registered by the fact that they do or don''t have a number against them. Merging table 3 into 1 might be the first thing. If registration is more complex than that, then you may have to set up more tables and associations to model it appropriately. Table 2 is already linked to table 1 via legacy ID1 - assuming these id''s are ok. So I''d get table2 into the database; pull out unique list of system contacts and create a separate table ''system_contacts'' (I''m assuming you''ve got some other fields to put against them). Table 2 then becomes a joining table. It already has the two fk''s - which you might relabel as agency_id and system_contact_id. Once this is done, you''ll have 3 tables and 3 models and using them would be a basic rails exercise. I probably haven''t grasped the full complexity of the relationships here, so I''ll stop there. -- Daniel Bush On Nov 13, 3:44 pm, Phil <philip...-bhJw6GgyJZ9p6SA07Sphdrpzq4S04n8Q@public.gmane.org> wrote:> Hi Daniel > > Thanks for replying so quickly. In a nutshell, yes. An Agency has many > People. Essentially the purpose of the project is to perform an > interim admin function to sync two systems. Hence there are two sets > of Primary keys and two tables. The third table is the output, where > it records the Agency business number to ensure that the Agency is > registered. Obviously there will be multiple Agency profiles for the > two systems with the primary keys for the agencies. Currently this is > being done manually. > > What I want to find out now is how to generate the view to encompass > the values from all three tables into one view, when I am using one of > the two system generated lists as a list for users to determine if a > client has been registered or not. E.g > > Agency ID 2 is clicked, which is linked to only one Agency Business > Number. How do I represent the values for this Agency ID 2 from the > other two tables? Obviously some Agency IDs will not have a > corresponding Agency Business Number in table 3 as they have not been > registered as yet, or in Table 2 for that matter. I am envisaging the > use of partials. > > I worked out how to generate primary and foreign keys. Currently I > have some code in my model that does this, but is not the best. > > Upload Model > def self.save > FasterCSV.foreach("D:/Rails/MySql/Migration/file.csv) do |row| > unless Agency_ID1.exists?(row[0]) > agency = Agency.new(:OrganisationName=>row[1],:TPID=>row[3]) do > |i| > i.Agency_ID1 = (row[0]) > end > agency.save > end > unless person.exists?(row[5]) > contact = person.new(:ContactFname=>row[6],:ContactLname=>row > [7],:ContactPhone=>row[8], > :ContactFax=>row[9],:ContactEmail=>row[10]) do |si| > i.ContactID = (row[5]) > end > contact.save > end > end > end > > It''s meant to be interim code that helps me load primary key values. > > I also have a search function working with Acts_as_ferret. > > This is the model code for Agency 2 (list) > > acts_as_ferret :fields => [:OrganisationName] > > This is the controller > > class SearchesController < ApplicationController > def index > if params[:q] > query = params[:q] > @Agency2 = Agency_ID2.find_with_ferret query, :page => params > [:page], :per_page => 50 > end > end > end > > This is the view in views/searches > > <table> > <thead> > <tr> > <td>OrganisationName</td> > <td>smartbuy ID</td> > <td>Supplier ABN</td> > <td>Supplier TPID</td> > </tr> > </thead> > <tbody> > <% @sbtradesuppliers.each do |s| %> > <tr> > <td><%= link_to s.OrganisationName, Agency2_path(s.id) %></td> > <td><%= s.Agency Business Number%></td> > <td><%= s.Agency ID 2%></td> > </tr> > <% end %> > </tbody> > </table> > <br> > <br> > <br> > <%= will_paginate @Agency2 %> > > My last question is, is this restful? > > Any help would be much appreciated. > > On Nov 13, 2:48 pm, Daniel Bush <dlb.id...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Nov 13, 11:10 am, Auch <philip...-bhJw6GgyJZ9p6SA07Sphdrpzq4S04n8Q@public.gmane.org> wrote: > > > > Hi > > > > I have limited success with rails and am trying very hard to > > > understand the MVC, DRY and RESTful concepts that Rails supports. > > > > What I am trying to do is to automate some data manipulation > > > procedures for legacy systems. I have three tables that I need to > > > import into the Rails application. > > > > Table 1 > > > Legacy_System_ID1, Agency_Business_Number, Agency_Name > > > belongs to Table 3 > > > belongs to Table 1 > > > > Table 2 > > > Legacy_System_ID2, Legacy_System_ID1, Legacy_System_Contact_ID, > > > Agency_Business_Number, Agency_name > > > has many Table 1 > > > > Table 3 > > > Agency_Business_Number, Agency_Name. > > > has many Table 1 > > > > These files are all in csv format. What I am having trouble with is > > > the concept of primary key ids. Rails does not like primary keys that > > > are not incremental. I know I can set the primary key to > > > Legacy_System_ID1 in Table 1 and set the foreign key to the same ID in > > > Table 2. > > > > The pinch is that I need to seperate the contact_ID from the > > > Legacy_System_ID2 of Table 2 into two tables and also add new entries > > > into Table 3, which is essentially a subset of Table 1 to keep track > > > of which Agencies with unique Agency_Business_Numbers are registered. > > > > Whats the best way to go about this in Rails? I am experimenting with > > > Instant Rails 2.02 > > > I think your model is saying something like > > System contact (a person) "has many" Agencies > > in a nutshell right? > > > -- > > Daniel Bush- Hide quoted text - > > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---