Re: [Rails] Re: Ahhh .count!

2010-05-12 Thread Jesse
On 5/12/10 6:08 PM, Rick DeNatale wrote: On Wed, May 12, 2010 at 4:47 PM, Jesse wrote: Sure thing: class Portal< ActiveRecord::Base has_many :users, :through => :programs end class Program< ActiveRecord::Base has_many :users, :through => :program_memberships end class User< Acti

Re: [Rails] Re: Ahhh .count!

2010-05-12 Thread Rick DeNatale
On Wed, May 12, 2010 at 4:47 PM, Jesse wrote: > Sure thing: > > class Portal < ActiveRecord::Base >  has_many :users, :through => :programs > end > > class Program < ActiveRecord::Base >  has_many :users, :through => :program_memberships > end > > class User < ActiveRecord::Base >  has_many :progr

Re: [Rails] Re: Ahhh .count!

2010-05-12 Thread Jesse
Sure thing: class Portal < ActiveRecord::Base has_many :programs has_many :users, :through => :programs end class Program < ActiveRecord::Base belongs_to :portal has_many :program_memberships, :dependent => :destroy has_many :users, :through => :program_memberships end class ProgramMe

Re: [Rails] Re: Ahhh .count!

2010-05-12 Thread Colin Law
On 12 May 2010 21:05, Jesse wrote: > Hi All, I am trying to do something similar and am running into an issue on > it > > I have a setup where > Portal has many Programs > program has many users through program_memberships > user has many portals through program_memberships Can you provide the fu

Re: [Rails] Re: Ahhh .count!

2010-05-12 Thread Jesse
Hi All, I am trying to do something similar and am running into an issue on it I have a setup where Portal has many Programs program has many users through program_memberships user has many portals through program_memberships I am trying to get it so that portal has many users through programs

[Rails] Re: Ahhh .count!

2010-05-11 Thread Marnen Laibow-Koser
David Zhu wrote: >> This seems like a good use case for has_many :through. > > > It sounds like an excellent case for has_many :through! > > haha i just did it using that method, it works great. thanks guys You're welcome! > > (Oh, am i posting right?) Yup. Best, -- Marnen Laibow-Koser http

[Rails] Re: Ahhh .count!

2010-05-11 Thread David Zhu
> This seems like a good use case for has_many :through. It sounds like an excellent case for has_many :through! haha i just did it using that method, it works great. thanks guys (Oh, am i posting right?) -- You received this message because you are subscribed to the Google Groups "Ruby on

[Rails] Re: Ahhh .count!

2010-05-10 Thread Marnen Laibow-Koser
David Zhu wrote: > OK, > > > But right now, i have-- > > Schools has many subjects, subjects has many teachers > > So instead of-- @totalcount = @school.subjects.count (that just > cuonts how many subjects are in the school) > > how can i count the teachers in that school? maybe something sim

Re: [Rails] Re: Ahhh .count!

2010-05-10 Thread Dhruva Sagar
Hi well there is no School.subjects.teachers in your case. You should do something like this : count = 0 @school.subjects.each {|s| count += s.teachers.count} It is possible that you could use inject above to shorten it a bit, but not sure about that in this case. On Tue, May 11, 2010 at 07:38,

[Rails] Re: Ahhh .count!

2010-05-10 Thread David Zhu
OK, But right now, i have-- Schools has many subjects, subjects has many teachers So instead of-- @totalcount = @school.subjects.count (that just cuonts how many subjects are in the school) how can i count the teachers in that school? maybe something similar to @totalcount = @school.subjects.