similar to: cant map foreign key in list view

Displaying 20 results from an estimated 4000 matches similar to: "cant map foreign key in list view"

2006 Feb 14
6
Multiple associations to the same class
Hi, I cannot seem to create associations like this: class Project < ActiveRecord::Base belongs_to :manager, :class_name => ''User'', :foreign_key => ''manager'' belongs_to :liaison, :class_name => ''User'', :foreign_key => ''liaison'' end p = Project.new p.manager => 1 trying to retrieve associated objects
2006 Jan 09
3
Include with two references of one model of the same table
Hey guys, I just came across this oddity, not sure what to make of it yet, but I think it might be incorrect behavior. When doing a @inst.find(:all, :include => ["hometeam", "awayteam"] ...) hometeam and awayteam are two references from a belongs_to that is of the same model and of the same table. I will get a pgerror stating that "matches", which 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
2006 Feb 09
2
Crazy @55 Inheritance
I have one table, called "people". Within this table, there are type "users", "managers".... etc. So, basic STI. Now, I want a "user" to have one manager, but a "manager" to have many "users". Since I don''t want to use HABTM... how do I set this relationship up seeing that :has_one, :belongs_to and :has_many don''t
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
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
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 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
2005 May 24
2
Deleting from a 'has_many' collection doesn't set the foreign key to NULL
Hi all, I have an Active Record problem. Having this classes declaration. class Sale < ActiveRecord::Base has_many :sale_line_items, :class_name ''SaleLineItem'' ... end class SaleLineItem < ActiveRecord::Base ... end When I try to delete an item in a Sale class method from sale_line_items (sale_line_items.delete(li)), it extracts ''li'' from
2006 Nov 07
4
non-"table_id" foreign key
Okay folks, I''m feeling like a fool. I''m sure I''m not the first person to run into this, but I can''t find the necessary info. Basically I need to create two tables. The first to hold actual content. And the second to link pairs of content records. For example, a "persons" table and a "friends" table that pairs up two person records.
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 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 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 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 Feb 03
1
Database Foreign Key - Basic question
Hi all I''m still waiting on my Agile Rails book to arrive - in the meantime ... As an exercise I''m making a Help Desk application. If I have a Problems table with two foreign keys to a People table, how do I set up my models, problems_controller list method, and then simply display say my problem submitter person? Here is what I have so far: Problems table with columns: id
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 Nov 02
4
Still Having Problems With :through When Going To Same Table... Help... please :-(
I am having a problem with doing a :through that goes back to the same table. The following are my two classes: >>>>> class User < ActiveRecord::Base has_many :spanks has_many :spanked, :through => :spanks, :source => :spanked_user has_many :was_spanked_by, :through => :spanks, :source => :user end class Spank < ActiveRecord::Base belongs_to :spanker,
2006 Mar 31
3
Complex Through Statement
Quick Overview: I have an ''Employee'', some ''Merchants'' and some ''Products''. A ''Merchant'' has many ''Products''. An ''Employee'' has multiple ''Merchants'', depending on their relationship. For example, the Employee may be the enrollment contact for one merchant and the
2012 Feb 14
2
Model with 2 foreign keys
Hi All, I''d like to integrate a simple user-oriented messaging system into my app. I have a Message model, with :from_user_id, and :to_user_id (for the user that sent and the user that recieved the message). Obivously, (User) has_many :messages will fetch the messages that a certain user has created, but not the ones that they have been sent. Currently, I have this: has_many :messages,