similar to: ActiveRecord: Reference same table twice

Displaying 20 results from an estimated 5000 matches similar to: "ActiveRecord: Reference same table twice"

2011 Jan 26
13
undefined method `model_name' for NilClass:Class
I am new to Ruby on Rails and have a very simple foreign key example that is driving me nuts. I am using Rails 3 under Windows Vista and have two tables: users and user_comments. user_comments.user_id should point to the user a comment is about. In my show view for user I have a link to the new method of user_comments to allow a comment to be created. This throws: Showing
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 May 14
3
Strange Database Mapping Question
Dear Rails List, I am new on the list so will assume straight away that this question has been answered before. As I can see no immediate way of searching the list, I will ask the question. I apologize in advance for any disruption this may cause. Question time: I am trying to write a web application for the staff at my office to play a form of virtual Super14. Its a bit like any of the
2006 Mar 07
13
Active Record - Can''t figure out relationship.
I have the following two tables: create table teams ( id int not null auto_increment, short_name varchar(12) not null, long_name varchar(50) not null, logo varchar(20) not null, primary key (id) ); create table rounds ( id int not null auto_increment, home_team_id int not null, away_team_id int
2006 Aug 24
1
AMD64 bug
The theora_unpack_comment casts a pointer-to-int to pointer-to-long. This is incorrect on AMD64, where ints and longs are of different size. On my system (Debian unstable, gcc 4.1) this causes players to crash when they reach the end of a movie. The patch below fixes this bug. --- libtheora-0.0.0.alpha7/lib/toplevel.c 2006-06-13 00:57:36.000000000 +0200 +++ libtheora-pdw/lib/toplevel.c
2001 Nov 11
1
Reading tags (again)...
Ok, so I finally got the id3/mp3 end of things worked out for the next release of QTagger and I'm back to implementing tag reading for Ogg Vorbis. I've got some code that will read tags, but I haven't been able to figure out how to write them. Here's the code that I'm using. It's a fine C/C++ mix. The code will eventually be in a C++ app, so I don't mind
2006 May 23
7
self-referencing has_many
Having a devil of a time finding records in a self-referencing has_many table relationship. Everything is working find looking at the has_many and the belongs_to relationship. But, when I try to find all "orphans", records that are neither a parent nor a child, I can not find a query that work in ActiveRecord. This query works in MySQL: SELECT * FROM templates LEFT JOIN templates
2006 Jul 13
5
Relationships: one model referencing same table for different data sets?
Hi, After I''ve saved, I want to display the Description from the Codes table that corresponds with the ID in the Cause table. Rails doesn''t seem to like that, because on my form, I have two sets of data in combo boxes that come from the Codes table. So, in the show template, I can''t do this: Cause of Death: <%= @cause.code.description %> Any ideas? The
2008 Jul 15
9
Beginner Question.
I''m just getting into RoR, coming from a long PHP background. So far I LOVE IT! I''m hitting a roadblock with updating my mysql database. For simplicities sake, I have 2 tables and here are the relevant columns. Table Users id name email Table Issues id createdby assignedto reportedby In my models I have everything mapped properly I believe. When I try to update the
2006 Jan 20
11
Userstamp Plugin
I''m pleased to announce a new plugin for Rails: Userstamp. You can read my blog post at http://www.delynnberry.com/articles/2006/01/20/userstamp-plugin and/or read all about it at the perminant page http://www.delynnberry.com/pages/userstamp. Any comments or suggestions for improvement are much appreciated. -- DeLynn Berry delynn@gmail.com http://www.delynnberry.com A dump of the Readme
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 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
2008 Jun 13
6
Newbie question on has_many
I have two classes: a Widget and a User. The User has an id that is referenced in two places on the Widget: owner_id and operator_id. How should I structure that reference for has_many? Thanks folks - I appreciate any help on this. --David --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2006 Jul 07
3
Newbie Model question (HABTM?)
All, If I have a table that has several discrete fields that all point to the same associated field, how do I model it. Specifically, If I have a project table that has 2 fields: specifying_company, and responsible_company. And one table of associated companies, how do I do the :belongs_to / :has_many stuff ie. For a given project company A may be writing the spec, but company B may be paying
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
2007 Jun 09
7
create 2 fk referencing the same table
Hi everyone! I have a problem with defining 2 fk referencing the same table. I have a Program table and a Team table. The Program should have an away team and a home team fk. From my understanding, "the fk column should be named after the class of the target table, converted to lowercase, with _id appended". But, in my case, I have 2 fk referencing the same table. How can I do this?
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 Jun 29
4
Multiple belongs_to
Let''s say I have a catalog with hotels. Each hotel belongs to a category (4-star, 5-star etc.) This is it''s official category.However, there is also a category that users assign and a category that "independent reviewers" assign. So I have this: hotels { id, category_id, reviewer_category, user_category } categories { id, name } class Hotel <
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 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