Displaying 20 results from an estimated 30000 matches similar to: "How do you reconcile foreign keys for forms?"
2005 Dec 14
5
belongs_to and multiple foreign keys
Hi all,
I''m confused about how I''m supposed to specify a belongs_to relationship when
the table includes multiple columns that reference the same parent table.
In my case I have a "schedules" table with "opened_by" and "closed_by" columns,
that both reference the "users" table. In theory, they can be two different
user ids.
table
2008 Apr 18
3
has_many and belongs_to with non-primary foreign keys
Hi,
I''m having a bit of trouble with my first Rails app.
----
I have two tables:
create_table :items do |t|
t.column :created_at, :timestamp
t.column :user_id, :int
t.column :text, :text
end
create_table :users do |t|
t.column :user_id, :int
t.column :name, :string
end
----
I''m trying to use the "user_id" field to link both tables, with each
user
2006 Apr 06
4
using two foreign keys to the same table
i am working on a task manager with ruby on rails. it is my first major
project, so i''m still gettng my feet wet as i learn.
i''ve been trying to use the built in relationships to link my tables
together, but i''m not able to use the same naming conventions. for each
task, it has a field for the creator, and another field for the
assignee. both of these fields
2005 Feb 09
1
cant map foreign key in list view
Hi
I have been struggling to get a foreign key in a list map to a readable
value in a lookup table
I have a list of projects and each project has a project_manager.
Project.rb
class Project < ActiveRecord::Base
has_one :project_manager, :class_name => "Users", :foreign_key =>
"manager_id"
end
The association above sais that a project_manager is in
2006 Jan 03
4
Set the foreign key constraint column name?
I am applying Rails to an existing schema and not sure how much the
existing developers will let me go in and rename things. So I need to
discover the limits of what I can change with Rails.
I''ve found set_table_name and set_primary_key, which have been very
useful.
If I have a "foo has_one :bar" relationship, but then in the bar table
my column is named "fooid"
2006 Jan 05
13
Naming convention for foreign keys
Hi,
In "Agilge Web Development With Rails" on page 217, an example of
foreign keys is shown.
I am however unable to find a definition of wheater the naming of the
index is significant. On the above mentioned page, this line is shown in
the example:
constraint fk_items_product foreign key (product_id) references
products(id)
In "fk_items_product", "items" is
2006 May 23
1
Validating a required relationship.
Hello,
I''m not sure if I''m missing something blindingly obvious here.
All the relationships that Rails comes with assume 0..n, yes? It''s
not a strict 1 to 1 or 1 to n because it''s optional. My question is
this -
What is the best way to implement a required relationship?
For example, if I require that a comment is made by a user (a user
has many
2011 Feb 26
1
How to manage the form of a model that has two foreign keys
Hi,
Basically I have two models: User and Godfather. The godfather table
has three columns:
- user_id (FK --> User)
- user_godfather_id (FK --> User)
- description (text)
Inside each model class, I am adding the following associations:
class User < ActiveRecord::Base
has_many :godfathers # for user_id
has_many :godfathers, :foreign_key =>
2006 Mar 31
18
Modelling Foreign Keys
Can someone point me to a reference or tutorial that shows how to map
foreign key relationships in the model?
For example given:
Users
id
name
email
Posts
id
user_id
title
How do I associate user_id with users.id in the Post and User models?
has_many and belongs_to don''t seem to do it.
--
Posted via http://www.ruby-forum.com/.
2006 Jun 23
2
Foreign key - relations
Hello,
I''ve got DB like this:
(roughly)
create table projects (
id int auto blabla,
name varchar(200),
user_id int,
sales_id int);
create table users (
id int auto..,
name varchar(50));
So project.user_id has a foreign key to user.id - all is good.
Everything works fine.
Now my question..
How can set a relationship from two different fields to the users table
??
Fx.
2006 Apr 11
5
Multiple "has" in ActiveRecord
Please excuse a newbie question, but I couldn''t find anything by
searching the archives.
What I want to know is how to have multiple references to the same
class/table within a class. For example, let''s say I have a table called
People:
create table people (
id serial8 primary key
,name);
which just holds a list of the people in the database. Then I have
another
2007 Oct 16
8
Using multiple foreign keys in views
I have a model, Game, that has_many :teams. There''s a home team and an
away team. I created two foreign keys, so each game can have two teams
associated with it. Here''s the Team model:
class Team < ActiveRecord::Base
belongs_to :game,
:class_name => ''Game'', :foreign_key => ''hometeam_id''
belongs_to :game,
:class_name =>
2006 Feb 26
3
Rails Naming Conventions
DB field names:
If I have a table that references 2 or more separate users from my users
table, is there a recommended naming convention for this situation? In
my case, I have 3 users associated with a record in my projects table:
requester_user_id
created_by
updated_by
I could name one of them "user_id", and then projects.user would work I
guess, but wouldn''t work
2006 Jun 22
1
Sharing primary key between two tables?
Hello,
I have an ActiveRecord question.
I have two tables, "customers" and "users". Those two tables really
should share their primary key, in order to have a "real" 1:1
relationship.
(I don''t mean to start a database-resign religious war, but I must say
that I do feel very uneasy about using ActiveRecord''s "normal" way,
which is to
2006 Jun 08
3
Foreign key confusion
I have 2 models right now: "users" and "posts". When a user creates a
post I would like their id to be recorded under "user_id" in the "posts"
table. Under the "user" model I have:
class User < ActiveRecord::Base
has_many :posts
end
And under the "posts" model I have:
class Post < ActiveRecord::Base
belongs_to :user
2006 Apr 07
6
Foreign Key naming convention override
I am working with an existing database and have to keep all table and
field names as they are. ''tblcustomers'' and ''tblitems'' are linked by the
''tblcustomers'' id field ''tblcustomersid''. In ''tblitems'', the foreign key
is called ''txtcustomerid''.
I have already set the customers model to
2006 Apr 02
7
RANT: belongs_to -> refers_to
Every once in a while, I pipe up and whine that "belongs_to" should really
be ''refers_to" [http://dev.rubyonrails.org/ticket/2130]. It''s time again.
I''ve got a bunch of stuff going onto eBay, so, like any good engineer, I
don''t just post it manually: I design a Rails-based inventory database that
creates a semantically-correct XHTML/CSS auction
2006 Jan 13
4
Single Table Inheritance (this is my 3rd post :( )
Hi Everyone,
I hope I get some feedback on my question. Here it goes.
I have a situation here, I have a company table and then using Single
Table inheritance it is of 3 types:
class Company < ActiveRecord::Base
end
class Vendor < Company
end
class Customer < Company
end
class Agent < Company
end
Now I have a active record Association
class QuoteSheet < ActiveRecord::Base
2011 Sep 16
4
belongs_to not working as
Hi,
I have a model tests_user and score which are associated with each other by
has_one and belongs_to association.
class TestsUser < ActiveRecord::Base
has_one :score, :foreign_key => :reg_no
end
class TestsUser < ActiveRecord::Base
belongs_to :tests_user, :foreign_key => :reg_no
end
where reg_no is a unique field in both the table!
score = Score.find(:first) gives me
2006 Aug 14
1
2 foreign keys to one table
Hi,
I have a messaging class that has to relationships to one table
belongs_to :user, :foreign_key => "from_id"
belongs_to :user, :foreign_key => "to_id"
At the min I can specify message.user.login and it will return the
username of last relationship to that table.
how can I get it to bring back both references
ie message.from.login and message.to.login
thanks
scott