similar to: Help with foreign keys, two keys joining same table

Displaying 20 results from an estimated 20000 matches similar to: "Help with foreign keys, two keys joining same table"

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
2006 Jan 13
4
missing foreign key fields in scaffold views
Is there any reason that foreign key fields do not show in any of the scaffold views ? project table: id serial primary key, category_id integer, user_id integer, name varchar, morestuff varchar foreign key (category_id) references categories(id), foreign key (user_id) references users(id) scaffold generated views only show name, morestuff fields
2006 Feb 04
1
Specifying multiple foreign keys to another table?
Hi, By convention, if I have a field that is a reference to another record in the `users` table, all I would need to do is to name the column `user_id` and RoR would know it is a reference. However currently I am working on a table that records `actions` that both impact on another user, with each action performed by another user. Thus I''d have 2 columns like `impacted_user_id` and
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 15
10
Scaffold with Foreign Key
I have two tables: ------------------------------ drop table if exists users; create table users ( id int not null auto_increment, username varchar(100) not null, password varchar(20) not null, firstname varchar(20) not null, lastname varchar(20) not null, primary key (id) ) TYPE = InnoDB; ------------------------------ drop 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 Feb 02
1
Two foreign keys to the same table
Hi, I''ve two tables: ProductLists (id, name, ...) Product (id,name,product_list_1_id, product_list_2_id, ...) How can I map the fields product_list_1_id and product_list_2_id to the ProductLists table in activerecord????? Thanks. -- Posted via http://www.ruby-forum.com/.
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/.
2009 Nov 20
3
Ensuring that foreign key is valid
I am trying to set up a validation in a model to ensure that a record can''t be saved unless the foreign key it belongs_to is a valid record. My model says: class Admin < ActiveRecord::Base validates_presence_of :user_id validates_numericality_of :user_id validates_uniqueness_of :user_id validates_associated :user belongs_to :user end but I can still create an admin
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
2011 Jun 11
1
Having a problem adding a foreign key
I keep getting this exception "SQLite3::SQLException: no such column: books.user_id: SELECT "books".* FROM "books" WHERE ("books".user_id = 4)" ,which sounds like there is no user_id in books table.So i just installed foreigner plugin and added " t.integer :user_id, :null => false" and "add_foreign_key(:books, :users)" in book
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 Mar 16
0
Conflicting Attributes in Model and Join Table...
Hi all, I''ve got a Post and User classes. The Post has a user_id attribute to point to the user that created it. I want to implement favorites, so I made Post and User both "has_and_belongs_to_many" and created a favorites join table. The join table has a post_id and a user_id column. Now when I get my post everything seems to be okay, but in some contexts, the user_id
2008 Mar 21
5
foreign key question
Hi- Say I have a db with following schema: MyTable: Id, name, user_id, date User: id, name, description I know that I want to add "belongs_to" in my "user" model but how can I enforce a proper constraint on the user_id in "MyTable"? Is this done using a has_one in the "MyTable" model? Thanks! --~--~---------~--~----~------------~-------~--~----~ You
2006 Feb 27
4
2 belongs_to to the same parent table
Hello! I have 2 table: users and buddies User: id, name, ... Buddy: id, user_id, user_buddy_id, ... So if you have 2 users 1,jack and 2,fred and fred is a buddy of jack, there is a Buddy object: id=1, user_id=1, user_buddy_id=2 I can declare only one belongs_to in Buddy and one has_many in User. And there is conflict if I had the second one (the first one is discarded) class User has_many
2013 Mar 25
1
validates presence of foreign key fails in nested form
I''m using accepts_nested_attributes as follows: class Timesheet < ActiveRecord::Base attr_accessible :status, :user_id, :start_date, :end_date, :activities_attributes has_many :activities, dependent: :destroy has_many :time_entries, through: :activities accepts_nested_attributes_for :activities, allow_destroy: true end class Activity < ActiveRecord::Base attr_accessible
2006 Feb 25
0
self referential habtm using join tables
All: I have been working on making a self-referential habtm relationship that uses a join model because I want to store info about the relationship. I have been using two sections from Chad Fowler''s "Rails Recipes" as a guide, "Self-referential Many-to-Many Relationships" and "Many to Many Relationships Where the Relationship Itself has Data". So far I have
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
2006 Feb 19
1
One Model from two Tables with no foreign keys
I would like to create a model that is based on two database tables: Table1 --------- id (PK) data1 Table2 ---------- id (PK) data2 There is a one-to-one relationship between the records of Table1 and Table2. (That is, for every record in Table1 there is a record with matching id in Table2 and vice versa). The problem is that I cannot alter the table schemas in any way, so I cannot add
2009 Apr 03
3
plyr and table question
Dear all, I'm puzzled by the following example inspired by a recent question on R-help, cc <- textConnection("user_id website time 20 google 0930 21 yahoo 0935 20 facebook 1000 25 facebook 1015 61 google 0940") d <- read.table(cc, head=T) ; close(cc) table(d$user_id) # count the