Hi, im trying to create an application for multiple customers, where data shouldnt be accessible to others. So ive added a customer_id to every db-table where it matters. Question: How can i add a Statement to find and other sql-commands so i just pull out the ones belong to the customer, without having to add :customer => customer to every find query? Whats the easiest way? a before_filter perhaps, or an overwrite of the find methods? Perhaps Im wrong with my idea anyway :) --~--~---------~--~----~------------~-------~--~----~ 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 Jul 17, 9:34 am, Tom Deal <s...-S/66wd8i11Xn/mjzvU0+Ig@public.gmane.org> wrote:> Hi, > im trying to create an application for multiple customers, where data > shouldnt be accessible to others. So ive added a customer_id to every > db-table where it matters. > Question: How can i add a Statement to find and other sql-commands so > i just pull out the ones belong to the customer, without having to > add :customer => customer to every find query? Whats the easiest way? > a before_filter perhaps, or an overwrite of the find methods?If you setup your associations correctly (ie customer has_many :things) then you can do customer.things.find ... Which is a normal find call, but which is scoped to that customer Fred> Perhaps Im wrong with my idea anyway :)--~--~---------~--~----~------------~-------~--~----~ 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 17 Jul., 11:12, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jul 17, 9:34 am, Tom Deal <s...-S/66wd8i11Xn/mjzvU0+Ig@public.gmane.org> wrote: > > > Hi, > > im trying to create an application for multiple customers, where data > > shouldnt be accessible to others. So ive added a customer_id to every > > db-table where it matters. > > Question: How can i add a Statement to find and other sql-commands so > > i just pull out the ones belong to the customer, without having to > > add :customer => customer to every find query? Whats the easiest way? > > a before_filter perhaps, or an overwrite of the find methods? > > If you setup your associations correctly (ie customer > has_many :things) then you can do > > customer.things.find ... > > Which is a normal find call, but which is scoped to that customer > > Fred > > > Perhaps Im wrong with my idea anyway :)Yes, exactly what i want to do, but is there a possibility to remove the customer at the beginning, so its more DRY? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---