Hi, I have looked around quite a bit, and haven''t found any workable solution to this. I am accessing an external/remote database from my rails app, in order to update a categories table. I cannot change the table structure of the remote database. it has a categories table with an id field but has a one to one relationship with a descriptions table. The descriptions table has no primary key, only a categories_id. Setting up a one-to-one relationship in my model allows me to load the description along with the category. But I need to be able to create a new category and description and cannot find a way around creating an ActiveRecord object without a primary key. Grateful for any suggestion of how to do this. I am wondering if I can use sql from within the model, but not quite sure how this would be done. Tony -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 17, 9:37 am, tonypm <tonypmar...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> Hi, > > I have looked around quite a bit, and haven''t found any workable > solution to this. > > I am accessing an external/remote database from my rails app, in order > to update a categories table. > > I cannot change the table structure of the remote database. it has a > categories table with an id field but has a one to one relationship > with a descriptions table. > > The descriptions table has no primary key, only a categories_id. > > Setting up a one-to-one relationship in my model allows me to load the > description along with the category. But I need to be able to create > a new category and description and cannot find a way around creating > an ActiveRecord object without a primary key. > > Grateful for any suggestion of how to do this. I am wondering if I > can use sql from within the model, but not quite sure how this would > be done. >Could you just tell rails that categories_id is the primary key? If it''s unique then that should be good enough (you''ll probably have to be a little careful when creating rows in this table though, as you''ll need to set categories_id each time) Fred> Tony-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
What is your rails version? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 17, 11:04 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Could you just tell rails that categories_id is the primary key? If > it''s unique then that should be good enough (you''ll probably have to > be a little careful when creating rows in this table though, as you''ll > need to set categories_id each time) >You are quite right Fred. I think I must have confused myself. I initially tried to bulk assign using create, but this resulted in the categories id not getting set. I thought i had tried using new and setting the categories_id before saving, but I must have confused myself. I have just tried it again and it works. Many Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.