On Jul 11, 3:16 pm, "Älphä Blüë" <[email protected]>
wrote:
> My setup:
>
> class Team
> has_many :schedules
> end
>
> class Schedule
> belongs_to :team
> end
>
> Teams Controller:
>
> @team = Team.find(params[:id])
> @team_id = params[:id]
> @schedule = Schedule.list(@team_id)
>
> Schedule Model:
>
> def self.list(teamid)
> named_scope :team_schedule, lambda { { :conditions => ['team_id = ?',
> teamid] } }
> team_schedule :joins => :team, :order => :date_scheduled
> end
>
Creating a named scope on the fly like that is really rather odd (and
completely unnecessary). i'm also not sure why you don't just do
@schedule = team.schedules.find :all, :order => '...'
If you want you can add a named scope on schedules with the order you
want and do
@schedule = team.schedules.with_my_ordering
> With my list method everything works great and as I want it too. My
> data returns:
>
> @team.name returns the team name
> @schedule.opponent returns the team's opponent
> @schedule.location returns the team's location (home/away/neutral)
> @schedule.date_played returns the team's scheduled date
>
> Great so far...
>
> Now I want to retrieve the team_id for the (opponent) inside the
> schedules table. Each team plays approx. 12 opponents. So, I would
> like to use an each statement to retrieve that bit of data at the same
> time I'm iterating through my table view...
>
Why not put the team_id for the opponent in the schedules table ?
Fred
> <% @schedule.each do |schedule| %>
> <%=h schedule.opponent %>
> <%=h schedule.opponent.team_id %>
> <% end %>
>
> .. I'm uncertain how to retrieve the team_id for the opponent listed in
> the schedules table. team_id is the foreign key for the teams table.
>
> Any help on how to write out this query would be appreciated.
> --
> Posted viahttp://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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---