jmazzi
2006-Oct-27 15:16 UTC
has_and_belongs_to_many - ensure only rows with there user_id are returned
Right now, im doing this in my controller: @message = Message.find(params[:id],:conditions => ["user_id = ?", @session[''user''].id]) Is there a way to do with in models them self so i dont have to pass in a user_id condition for all finds, deletes, etc? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jmazzi
2006-Oct-27 15:16 UTC
has_and_belongs_to_many - ensure only rows with there user_id are returned
Right now, im doing this in my controller: @message = Message.find(params[:id],:conditions => ["user_id = ?", @session[''user''].id]) Is there a way to do with in models them self so i dont have to pass in a user_id condition for all finds, deletes, etc? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Tom Mornini
2006-Oct-27 15:47 UTC
Re: has_and_belongs_to_many - ensure only rows with there user_id are returned
On Oct 27, 2006, at 8:16 AM, jmazzi wrote:> Right now, im doing this in my controller: > > @message = Message.find(params[:id],:conditions => ["user_id = ?", > @session[''user''].id]) > > > Is there a way to do with in models them self so i dont have to > pass in > a user_id condition for all finds, deletes, etc?@session[''user''].messages.find(params[:id]) -- -- Tom Mornini, CTO -- Engine Yard, Ruby on Rails Hosting -- Reliability, Ease of Use, Scalability -- (866) 518-YARD (9273) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2006-Oct-27 16:04 UTC
Re: has_and_belongs_to_many - ensure only rows with there user_id are returned
On Fri, 27 Oct 2006, jmazzi wrote:> > Right now, im doing this in my controller: > > @message = Message.find(params[:id],:conditions => ["user_id = ?", > @session[''user''].id]) > > Is there a way to do with in models them self so i dont have to pass in > a user_id condition for all finds, deletes, etc?class User < ActiveRecord::Base has_many :messages end Then you can do the following once you have a valid user. @user.messages --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jmazzi
2006-Oct-27 17:05 UTC
Re: has_and_belongs_to_many - ensure only rows with there user_id are returned
Can that be used in the message contoller? @user.messages --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---