On Feb 16, 2011, at 3:03 PM, kevinpfromnm wrote: > has_one is poorly supported. I'd probably do it in the permissions: > > in comment model > > belongs_to :post > belongs_to :user, :creator => true > > def create_permitted? > return false unless user.signed_up? > return false if post.comments.*.user.includes? acting_user > user_is? acting_user > end
A tiny optimization on this would probably be better: def create_permitted? return false unless user.signed_up? return false if post.comments.*.user_id.includes? acting_user.id user_is? acting_user end or even (although this is getting harder to read): def create_permitted? return false unless user.signed_up? return false if post.comments.exists?(:user_id => acting_user.id) user_is? acting_user end This will completely avoid even loading the other comments (it does a single select with the conditions supplied + the association conditions). --Matt Jones -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
