I have two databases in SQLite with the same schema. The other database was populated by an external customer and then returned. I want to use ActiveRecord to do the comparison. I am not sure of the best way to access the tables in each database with ActiveRecord models. I could change the connection dynamically whenever I want to switch between the databases, but this would seem to be clumsy and error prone. Another approach would be to create a 2nd set of classes at runtime which cloned the original ActiveRecord model classes and inherits from a different base class with a different connection. If anyone has done anything like this or has any suggestions on the best course of action, I would appreciate it. Thanks in advance, Don McClean --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Honestly, were it me, I would just copy the model files, rename them to something like ModelOtherDB, and use establish_connection and set_table_name. Might be somewhat clunky, and might not be the route to go if this is something you''re going to need to abstract to multiple applications, but if it''s just the one, then that should probably work fine. On 3/13/07, Don.Mc <Don.McClean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I have two databases in SQLite with the same schema. The other > database was populated by an external > customer and then returned. I want to use ActiveRecord to do the > comparison. > > > I am not sure of the best way to access the tables in each database > with ActiveRecord models. I could > change the connection dynamically whenever I want to switch between > the databases, but this would seem to be clumsy and error prone. > > Another approach would be to create a 2nd set of classes at runtime > which cloned the original ActiveRecord > model classes and inherits from a different base class with a > different connection. > > If anyone has done anything like this or has any suggestions on the > best course of action, I would appreciate it. > > Thanks in advance, > Don McClean > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Luke, Thanks for the quick response. It is something that I will probably need to abstract for future application. I believe your suggestion is good, I would probably something similar at runtime if possible to create the additional classes and connection. Thanks for your comment on ''set_table_name'', I forgot about that completely. Regards, Don On Mar 13, 12:07 pm, "Luke Ivers" <technod...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Honestly, were it me, I would just copy the model files, rename them to > something like ModelOtherDB, and use establish_connection and > set_table_name. > > Might be somewhat clunky, and might not be the route to go if this is > something you''re going to need to abstract to multiple applications, but if > it''s just the one, then that should probably work fine. > > On 3/13/07, Don.Mc <Don.McCl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I have two databases in SQLite with the same schema. The other > > database was populated by an external > > customer and then returned. I want to use ActiveRecord to do the > > comparison. > > > I am not sure of the best way to access the tables in each database > > with ActiveRecord models. I could > > change the connection dynamically whenever I want to switch between > > the databases, but this would seem to be clumsy and error prone. > > > Another approach would be to create a 2nd set of classes at runtime > > which cloned the original ActiveRecord > > model classes and inherits from a different base class with a > > different connection. > > > If anyone has done anything like this or has any suggestions on the > > best course of action, I would appreciate it. > > > Thanks in advance, > > Don McClean--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Don.Mc wrote:> I have two databases in SQLite with the same schema. The other > database was populated by an external > customer and then returned. I want to use ActiveRecord to do the > comparison.Read /Rails Recipes/; it shows how to open two databases at the same time. (But seriously, if this is a one-shot with sqlite3, I would just .dump the databases and diff them... -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Phlip, Thanks, I looked at the Recipes book previously, it is only applicable when you have different schemas in the two databases. And it''s not a one-shot deal, unfortunately, I need an long term automated solution. Thanks, Don On Mar 13, 12:30 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Don.Mc wrote: > > I have two databases in SQLite with the same schema. The other > > database was populated by an external > > customer and then returned. I want to use ActiveRecord to do the > > comparison. > > Read /Rails Recipes/; it shows how to open two databases at the same time. > > (But seriously, if this is a one-shot with sqlite3, I would just .dump > the databases and diff them... > > -- > Phlip > http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 3/13/07, Don.Mc <Don.McClean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Luke, > Thanks for the quick response. It is something that I will probably > need to > abstract for future application. I believe your suggestion is good, I > would > probably something similar at runtime if possible to create the > additional classes and > connection. Thanks for your comment on ''set_table_name'', I forgot > about > that completely. > > Regards, > DonSo, just thought I''d drop you another note showing some neat stuff you can do that will probably help. class User < ActiveRecord::Base end (somewhere else in your code) UserOtherDB = User.dup UserOtherDB.class_eval <<EOS establish_connection :blah => blah, :blah => blah set_table_name ''users'' EOS --~--~---------~--~----~------------~-------~--~----~ 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 helps! Thanks Luke On Mar 13, 1:04 pm, "Luke Ivers" <technod...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 3/13/07, Don.Mc <Don.McCl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Luke, > > Thanks for the quick response. It is something that I will probably > > need to > > abstract for future application. I believe your suggestion is good, I > > would > > probably something similar at runtime if possible to create the > > additional classes and > > connection. Thanks for your comment on ''set_table_name'', I forgot > > about > > that completely. > > > Regards, > > Don > > So, just thought I''d drop you another note showing some neat stuff you can > do that will probably help. > > class User < ActiveRecord::Base > end > > (somewhere else in your code) > UserOtherDB = User.dup > UserOtherDB.class_eval <<EOS > establish_connection :blah => blah, :blah => blah > set_table_name ''users'' > EOS--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---