Displaying 20 results from an estimated 30 matches for "team_id".
2009 Jul 29
5
[newbie] double relationships in database
I have the following tables
teams
id :string
name :string
and
matches
id:
home_team :team_id
visitor_team :team_id
how can I reflect that kind of relationship in a RoR model?
thanks and keep up the good work.
2006 Jan 31
1
Updating :has_many - :through related items
...select> tags for the "blue" side, using
@match_teams[3] through 5)
The Edit controller defines @match_teams as:
@match = Match.find(params[:id])
@teams = Team.find(:all, :order => "number")
@match_teams = []
@match.competitions.each do |team|
@match_teams << team.team_id
end
Now in the update method I''m doing this, but it looks messy and
doesn''t seem to update the correct records:
@match = Match.find(params[:id])
if @match.update_attributes(params[:match])
for i in 0..2
if @match.competitions[i].team_id != params[:Red][i] then
@match...
2009 Jul 17
19
I need help saving table data from a rake task
I need to find out how I can create and save a large dataset to a table
based on multiple returned arrays from a Rake task.
Here is my example using just two arrays (there are 14 in this
particular rake task):
update_tsos_offense = TsosOffense.new
to_team_id, to_ppcs = update_tsos_offense.calculate_tsos(TotalOffense,
"ydspgm", "desc")
ro_team_id, ro_ppcs = update_tsos_offense.calculate_tsos(RushingOffense,
"ydspg", "desc")
This task starts with creating a new object (TsosOffense) which is the
model that houses t...
2008 Sep 17
0
permalink_fu and classes with different primary_key than id?
Has anyone else had problems with this scenario?
class Team < ActiveRecord::Base
# Primary key
self.primary_key = ''team_id''
has_many :players, :foreign_key => :team_id
has_permalink :city, :param => true
end
I am getting all kinds of trouble - that goes away if I comment out
the has_permalink declaration.
With PermalinkFu:
>> fs = Team.new
=> #<Team team_id: nil, abbr: nil, city: nil...
2010 Jan 25
0
has_many, :finder_sql, setting attributes
...ram_id
JOIN users AS u ON up.user_id =
u.user_id
WHERE u.user_id = #{id}''
has_many :teams, :finder_sql => ''SELECT t.* FROM teams AS t
JOIN user_teams AS ut ON ut.team_id =
t.team_id
JOIN user_programs AS up ON
up.user_program_id = ut.user_program_id
JOIN users AS u ON up.user_id =
u.user_id
WHERE u.user_id = #{id}''
end
class UserProgr...
2009 Jun 25
7
Join Tables
...he singular name.
However, I''ve installed both of the following plugins:
redhillonrails_core
foreign_key_migrations
So, as an example, let''s say I created 32 tables with the following type
of information:
def self.up
create_table :rushing_offenses do |t|
t.integer :team_id
t.string :name
t.integer :games
t.integer :carries
t.integer :net
t.float :avg
t.integer :tds
t.float :ydspg
t.timestamps
end
end
And I want to create a join table for the team_id to associate with all
those tables:
How would I define the self...
2006 Apr 03
2
HABTM migrations
Bad rails day for Matt-
In a migration, for a habtm:
create_table :teams_users do |t|
t.column :team_id, :integer
t.column :user_id, :integer
end
Ok, fine. In a controller (well really a migration script):
@user.teams << Team.find( 3 )
And the SQL pumped at my server is:
INSERT INTO teams_users (`team_id`, `id`, `user_id`) VALUES (3, 3, 34)
Which promptly fails...
2006 Jul 18
1
Saving an ActiveRecord object
...{RAILS_ROOT}/app/models/player.rb:17:in `create_player''
#{RAILS_ROOT}/app/controllers/team_controller.rb:53:in `add_player''
And my Player model is:
class Player < ActiveRecord::Base
belongs_to :team
# Crea un jugador con los valores por defecto
def Player.create_player(team_id)
player = Player.new
player.relate_to_team(team_id)
player.save <-------------------------------- LINE 17
return player
end
# Relaciona el jugador con un equipo
def relate_to_team(team_id)
@team_id = team_id
end
end
What means that error? Do Player class hasn'...
2006 Jul 26
8
team captain - habtm w/has_one...
the below...
class User < ActiveRecord::Base
has_and_belongs_to_many :teams
class Team < ActiveRecord::Base
has_and_belongs_to_many :users
has_one :captain, :class_name => ''User''
produces the error...
Mysql::Error: Unknown column ''users.team_id'' in ''where clause'': SELECT *
FROM users WHERE (users.team_id = 1) LIMIT 1
i realize the error - and my current solution is to add user_id to
team...
then i have...
class Team < ActiveRecord::Base
has_and_belongs_to_many :users
def captain
User.find(user_...
2006 Jun 22
4
Filter on variable
Hi all,
I have a question about filtering on a variable.
If I have the following code in my controller to select a list of
users
> @allusers = User.find(:all,
> :conditions => [''team_id = ?'', @params["id"],
> :order => ''created_at'')
Is there an easy way to find out all users who were created one year
ago?
Can I do find against a variable?
Thanks.
Arnold.
--
Posted via http://www.ruby-forum.com/.
2008 Jan 27
4
(REST) Nested routes
...les with nested routes. I have three models: Team,
Tournament and TeamTournaments
class Team < ActiveRecord::Base
has_many :tournaments, :through => :team_tournaments
has_many :team_tournaments
class TeamTournament < ActiveRecord::Base
belongs_to :team, :foreign_key => ''team_id''
belongs_to :tournament, :class_name => ''League'', :foreign_key =>
''tournament_id''
class Tournament < ActiveRecord::Base
has_many :teams, :through => :team_tournaments
has_many :team_tournaments
So it''s a N-M relationship betw...
2009 Jul 16
9
Please help me understand how arrays are translated in rails
...uby I
haven''t found a mental connection with how I can assign variables to
arrays..
Take for example:
def calculate_tsos(model, datavar, teamvar, valvar)
var = model.compiled_this_week.find(:all)
var.each_with_index do |rows, i|
puts "#{model} [ Row #{i} | Team ID = #{rows.team_id} | Team =
#{rows.team.name} | #{datavar} = #{rows.__send__(datavar)}"
end
end
This will give me:
TotalOffense [ Row 0 | Team ID = 5 | Team = Tulsa | ydspgm = 569.86
TotalOffense [ Row 1 | Team ID = 47 | Team = Houston | ydspgm = 562.77
TotalOffense [ Row 2 | Team ID = 20 | Team = Oklahoma...
2005 Dec 31
6
habtm recursion via destroy_without_callbacks
I am having a problem with two models that each have a HABTM
relationship to the other. For example:
CREATE TABLE people (id INT, name TEXT);
CREATE TABLE teams (id INT, name TEXT);
CREATE TABLE people_teams (person_id INT, team_id INT);
The person model has:
has_and_belongs_to_many :teams
And the team model has:
has_and_belongs_to_many :people
The trouble comes when trying to destroy something, I end up with a
recursive stack sequence that looks something like:
(eval):7:in `destroy_without_habtm_shim_for_teams'...
2006 Jan 23
15
Looking for DB/Model Design Suggestions
Hi,
I''m working on an app - my first Rails - and am looking for some
suggestions on the best way (or good way) to set up my models / DB. In
general there are teams and matches; a team will participate in multiple
matches, and in each match there will be 6 teams - 3 vs. 3.
I''m going to want to be able, for a particular team, pull up all matches
for that team, to display a
2006 May 14
3
Strange Database Mapping Question
...s.
In the models, I was thinking that the game model would include,
"has_many :teams"
and the team model would include, "belongs_to :game"
When I then look at the scaffold list for Games the home and away teams do not
show up.
Is there a better way to name the home and away team_id''s in the games table
that will fix this?
or is there another more elegant way to handle this.
Thanks for your patience reading this and I look forward to hearing from you,
Dave Latham
@NewZealand.Auckland
2006 Apr 16
1
Design question: Years/Teams/Students
...name
but a student can also have many teams (eg summer/winter abd over a
number of years) . .
Is there a problem with this? Doesn''t it just mean that there will be a
student table with:
id
lastname
firstname
middlename
and a separate "studentteams" table with:
id
student_id
team_id
?
Thanks,
Phil.
--
Philip Rhoades
Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275)
GPO Box 3411
Sydney NSW 2001
Australia
Mobile: +61:(0)411-185-652
Fax: +61:(0)2-8221-9599
E-mail: phil@pricom.com.au
2006 Jan 13
2
newbie: access model inside a model
Hi everybody,
I''ve started to learn Ruby on Rails with the two books, of course I''m
experimenting outside
the examples in the book and walking against some things I didn''t learn
yet. so here''s the question:
Is it possible to access one model from within another? Actually I have
a Many to Many relationship
between tables and I''m trying to realize
2006 Jan 09
3
Include with two references of one model of the same table
...atches" where I think should be two
selects on two aliases of "matches".
Heres some code below to better understand what I''m talking about.
class Match < ActiveRecord::Base
belongs_to :hometeam, :class_name => "TeamsSeason", :foreign_key =>
"hometeam_id"
belongs_to :awayteam, :class_name => "TeamsSeason", :foreign_key =>
"awayteam_id"
end
class TeamsSeason < ActiveRecord::Base
has_many :hometeam, :class_name => "Match", :foreign_key =>
"hometeam_id", :dependent => :destroy
ha...
2009 Jan 08
5
There is already an object named 'schema_migrations' in the database
I''ve created a table in a SQL Server database using a migration,
successfully.
I''ve tried to change the name of a column in the table and got the
error message above when running ''rake db:migrate''.
Previously I have developed using MySQL and Sqlite and migrations have
worked successfully. This is an error I have not seen before.
Has anybody seen this and worked
2006 Jul 28
2
has_many :through with multiple paths
...gle
Person record could be on 6 different teams at the same time in
different roles. the same person could even be on the same team multiple
times in different roles.
I am not 100% sure how to go about this. I am thinking that I will need
something like an intermediate record.
teams_people
id
team_id
people_id
role
I would then have (I think) to have methods in the Team model that will
find each person in the @team.people array based on the role.
I the end I want a view to have something like:
Team Name
Manager: Person1, Person 4
Programmer: Person2, Person 3
Designer: Person2
Lackey: Perso...