On Jul 11, 6:34 pm, "Älphä Blüë" <[email protected]> wrote: > Another query should be made against each opponent returned within the > first query finding their subsequent ID in the teams table. > > How would I implement such a query? Define each returned opponent as a > param? Pass the param to another method within teams? > > This is the issue I would like to see answered. I really should not > have to create another id column in my schedules for the opponents. > Why? It's redundant data. >
> Opponents are also Teams that have opponents in the schedules table... > > There should be a way to cross check their name and find their id in > either the schedules table or the teams table. If you see my diagram > above it shows that Florida for instance has 12 opponents but you also > see that the team_id shows Florida as 10. > > If I did a search for Florida St. they would have Florida as their week > 12 opponent in the schedules table. So, this means that there is a team > name of Florida (somewhere in the schedules table) that already houses > an team_id of 10. > > I just don't see why something like this is so difficult to achieve? I > can create the entire query in mysql but I shouldn't have to create a > complete mysql query in rails for something like this. I've defined the > relationships between these tables so they are associated. That means I > should be able to pull any data from either table at anytime.. Well having the names of teams in the schedules table is the redundant data in my opinion. Associations work through primary keys and so on, associating via things like names just aren't that common (because names are often non unique, subject to change etc...). Having defined an association via the primary key doesn't magically define associations through other attributes. You could easily call Team.find_by_name to find the team with appropriate name or add a method to schedule that returned that but I fail to see why you wouldn't just store the opponent_id on the schedules table and be done with it. In recent versions of rails has_many/belongs_to have a :primary key association for creating associations that target an attribute other than the primary key, but again the name isn't a great candidate for this (more useful when you have some business provided unique identifier like an ISBN) Fred > -- > 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 -~----------~----~----~----~------~----~------~--~---

