Hi all I have a model called,article which belongs_to user so in article.rb belongs_to :user and in user.rb has_many :posts, :dependent => :nullify, :class_name => ''Article'' so now @user.posts is giving the posts of the user Now like,without using any named_scope, i would want @user.posts to give out only the posts which were published before 10 days. I know i can use a named_Scope But i want to directly use @user.posts alone to get the above result. Is it possible to do this?? Thanks In Advance, Charanya -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Is it possible to do this??Look up "default_scope" -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
has_many :posts, :conditions => ''created_at >= #{10.days.ago}'' On Feb 12, 7:12 pm, Charanya Nagarajan <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi all > > I have a model called,article which belongs_to user > so in article.rb > belongs_to :user > > and in user.rb > has_many :posts, :dependent => :nullify, :class_name => ''Article'' > > so now @user.posts is giving the posts of the user > > Now like,without using any named_scope, > i would want @user.posts to give out only the posts which were published > before 10 days. > > I know i can use a named_Scope > But i want to directly use @user.posts alone to get the above result. > > Is it possible to do this?? > > Thanks In Advance, > > Charanya > -- > Posted viahttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
That''ll return all posts that were created in the 10 days before the application was started (because 10.days.ago is evaluated in the class body). To return all posts that were created in the 10 days before the query is run, you want: has_many :posts, :conditions => proc { [''created_at >= ?'', 10.days.ago] } Mat On Fri, Feb 12, 2010 at 05:51, Jared Armstrong <jared.armstrong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> has_many :posts, :conditions => ''created_at >= #{10.days.ago}'' > > On Feb 12, 7:12 pm, Charanya Nagarajan <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Hi all >> >> I have a model called,article which belongs_to user >> so in article.rb >> belongs_to :user >> >> and in user.rb >> has_many :posts, :dependent => :nullify, :class_name => ''Article'' >> >> so now @user.posts is giving the posts of the user >> >> Now like,without using any named_scope, >> i would want @user.posts to give out only the posts which were published >> before 10 days. >> >> I know i can use a named_Scope >> But i want to directly use @user.posts alone to get the above result. >> >> Is it possible to do this?? >> >> Thanks In Advance, >> >> Charanya >> -- >> Posted viahttp://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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.