class Place < ActiveRecord::Base attr_accessible :address, :city, :name, :description has_many :meetings end Class Meeting < ActiveRecord::Base attr_accessible :start_at, :place_id, :title, :end_at belongs_to :place has_many :participations has_many :players, :through => :participations end class Participation < ActiveRecord::Base attr_accessible :meeting_id, :player_id end class Player < ActiveRecord::Base attr_accessible :id, :city, :first_name, :gear, :last_name, :email, :password, :password_confirmation has_many :participations has_many :meetings, :through => :participations end how to select all meetings in the specified city together with their addresses and players? -- 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 https://groups.google.com/groups/opt_out.
On 9 October 2012 17:29, Eugeni Kurtov <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> class Place < ActiveRecord::Base > attr_accessible :address, :city, :name, :description > has_many :meetings > end > > Class Meeting < ActiveRecord::Base > attr_accessible :start_at, :place_id, :title, :end_at > > belongs_to :place > has_many :participations > has_many :players, :through => :participations > > end > > class Participation < ActiveRecord::Base > attr_accessible :meeting_id, :player_idYou need belongs_to metting and player here.> end > > class Player < ActiveRecord::Base > attr_accessible :id, :city, :first_name, :gear, :last_name, :email, > :password, :password_confirmation > > has_many :participations > has_many :meetings, :through => :participations > end > > how to select all meetings in the specified city together with their > addresses and players?By a city do you mean a Place or a string in player.city? Colin -- 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 https://groups.google.com/groups/opt_out.
Colin Law wrote in post #1079115:> On 9 October 2012 17:29, Eugeni Kurtov <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> has_many :players, :through => :participations >> >> end >> >> class Participation < ActiveRecord::Base >> attr_accessible :meeting_id, :player_id > > You need belongs_to metting and player here.Sure thing, sorry cleaned it up by mistake.> >> how to select all meetings in the specified city together with their >> addresses and players? > > By a city do you mean a Place or a string in player.city? > > ColinI mean a Place, as a Meeting occurs in some Place, so it will be all Meetings in all Places filtered out by the city. Also I discover that it is possible to use counter_cache to have a number of Players, who joined the Meeting in the player_cache column, is that right? -- 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 https://groups.google.com/groups/opt_out.
On 9 October 2012 18:53, Eugeni Kurtov <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #1079115: >> On 9 October 2012 17:29, Eugeni Kurtov <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> has_many :players, :through => :participations >>> >>> end >>> >>> class Participation < ActiveRecord::Base >>> attr_accessible :meeting_id, :player_id >> >> You need belongs_to metting and player here. > Sure thing, sorry cleaned it up by mistake. >> >>> how to select all meetings in the specified city together with their >>> addresses and players? >> >> By a city do you mean a Place or a string in player.city? >> >> Colin > > I mean a Place, as a Meeting occurs in some Place, so it will be all > Meetings in all Places filtered out by the city.You are using the word city again, so once again it is not clear what you mean. Back to the original question, if you have a place, @place for example, then its meetings are @place.meetings and for each meeting the players are meeting.players. You have also asked for the address of the meeting, but you know that already as it is in @place.> Also I discover that it is possible to use counter_cache to have a > number of Players, who joined the Meeting in the player_cache column, is > that right?I have not used counter_cache but i believe it can be used for such things. Colin -- 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 https://groups.google.com/groups/opt_out.