On Dec 15, 2010, at 12:04 PM, Colin Law wrote:
> On 15 December 2010 17:01, Tim Shaffer <timshaffer@me.com> wrote:
>> You could just use a method instead...
>>
>> class User < ActiveRecord::Base
>>
>> has_many :payments
>>
>> def testing_payments
>> payments.where(:testing => testing)
>> end
>
> That would be even better as a named scope.
>
> Colin
Actually, it would be better if it worked:
class User < ActiveRecord::Base
has_many :payments
def testing_payments
payments.where(:testing => true) # testing is a local?
end
end
somebody = User.find(params[:id])
Then, you could say:
somebody.testing_payments
Or add a scope to Payment
class Payment < ActiveRecord::Base
belongs_to :user
scope :testing, where(:testing => true)
end
And you'd say:
somebody.payments.testing
Either would work. If testing is a instance method of User, then the
original suggestion might actually be "better."
-Rob
Rob Biedenharn
Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/
rab@GaslightSoftware.com http://GaslightSoftware.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@googlegroups.com.
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.
No comments:
Post a Comment