is it possible to use scope in model relationships?
class Post < ActiveRecord::Basescope :published, where(:published, true)
class User < ActiveRecord::Basehas_many :posts
has_many :published_posts, class_name: 'Post' ..... here I would like to
use the same conditions of scope published without rewrite them
I know that I can write a method in User class instead of the has_many
relationship, something like
def published_postreturn self.posts.published
but in this way I can't use the include: in the to_json method
and I can't use method: instead beacuse I have to use also the only:
attribute to filter the attributes in the json output
Thanks to all
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Vb3ZXv0zyZIJ.
To post to this group, send email to firstname.lastname@example.org.
To unsubscribe from this group, send email to email@example.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.