I have a model which contains a large dataset which is unmodifiable. I contains a relation of ids to names for several item types lumped together, not idea I know. I have a model which needs two associations, both of which will link to this model above, but with different names. For example, lets say the dataset contains a list of furniture. Ids 1-10 might be tables and 11-20 might be chairs. Lets say the other model defines a room. A room should be able to have one table and one chair. Unfortunately, as they both refer to the same model, I''m a loss on how to do it. Not even sure if it''s possible, which will be a real pain as I can''t modify the larget dataset at all. Grateful for some pointers, if anyone actually understands my problem :) -- 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-/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 https://groups.google.com/groups/opt_out.
On Sun, Jul 22, 2012 at 5:13 PM, Matt Harrison <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Lets say the other model defines a room. A room should be able to have > one table and one chair. Unfortunately, as they both refer to the same > model, I''m a loss on how to do it.You could have attributes called table and chair, each referring to a furniture. Upon saving, have a validation check that table is a table and chair is a chair. I''d recommend doing this with a furniture_type method, rather than directly checking the range; if you somehow manage to be able to change this ID silliness, you can then have the method check something else instead (such as a enumerated type attribute). -Dave -- Dave Aronson, Cleared/Remote Ruby on Rails Freelancer (NoVa/DC/Remote); see www.DaveAronson.com, and blogs at www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.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-/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 https://groups.google.com/groups/opt_out.
On Sun, Jul 22, 2012 at 2:13 PM, Matt Harrison <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> For example, lets say the dataset contains a list of furniture. Ids 1-10 > might be tables and 11-20 might be chairs. > > Lets say the other model defines a room. A room should be able to have > one table and one chair. Unfortunately, as they both refer to the same > model, I''m a loss on how to do it. Not even sure if it''s possible, which > will be a real pain as I can''t modify the larget dataset at all.class Furniture < ActiveRecord::Base; end class Table < Furniture default_scope where( ... check id here... ) end class Chair < Furniture -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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 https://groups.google.com/groups/opt_out.
# two premature sends today; fingers sticking to keyboard here in # 90+degree San Jose - sorry! class Furniture < ActiveRecord::Base; end class Table < Furniture default_scope where( ... check id here... ) end class Chair < Furniture default_scope where( ...check id here... ) end HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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 https://groups.google.com/groups/opt_out.
Thanks guys, I will have a fiddle and see what I can do with your suggestions. It''s really a rediculous way to keep the data and if it was up to me I can guarantee it would be done differently :) Thanks -- 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-/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 https://groups.google.com/groups/opt_out.
Got it working perfectly now. I''m not going to put much checking in, if I leave a couple of small gaps and something gets mis-associated, I can push harder for an overhaul of the dataset :) Thanks again -- 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-/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 https://groups.google.com/groups/opt_out.