similar to: Foreign key with 2 or more fields in a relationship

Displaying 20 results from an estimated 20000 matches similar to: "Foreign key with 2 or more fields in a relationship"

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 Jun 21
1
Migration with foreign key won''t work
Hi all I use the plugin which supports foreign keys with migrations: http://wiki.rubyonrails.org/rails/pages/Foreign+Key+Schema+Dumper+Plugin/versions/12 I have created the following migration file: class AddArtistsTable < ActiveRecord::Migration def self.up create_table :artists, :force => true do |t| t.column :name, :string, :limit => 100 t.column :artist_type_id,
2009 Feb 21
2
Foreign-key confusion
Hi, I am a bit confused about managing the relationship between two of my tables: I have developed a script using scRUBYt that scrapes data from a website and dumps the following four fields into my Shows table: class CreateShows create table :shows do |t| t.string :date t.string :venue t.string :info t.string :comics The second table I created is called Theatres: class
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 Jul 10
10
has_many :through and foreign key parameters
I just took my HABTM and turned it into a :through since my join table has another "non-joiny" attribute. I went from this: has_many_and_belongs_to :jobs, :join_table => ''tablename'', :foreign_key => ''x'', :association_foreign_key => ''y'' to this: has_many :jobs, :through =>
2007 Aug 30
1
belongs_to with foreign keys that reference non primary key columns
Hello, I have a situation where the foreign key into a table doesn''t correspond to that table''s primary key: my_table ------------- id (pk) name ... other_table -------------- id (pk) my_table_name (fk references my_table(name)) ... I want to be able to say something like: class OtherTable < ActiveRecord::Base belongs_to :my_table, :foreign_key => { :my_table_name
2006 Apr 11
1
Foreign Keys
Hi, My tables are as follows: "tblusers" - primary key "TblUsersID" "tblregisteredphones" - primary key "TblRegisteredPhonesID" - foreign key "intUserID" My models are as follows: class Registeredphone < ActiveRecord::Base set_table_name "tblregisteredphones" belongs_to :user, :foreign_key
2006 Apr 06
0
Table w/ 2 columns feat. the same foreign key (accessing?)
I have a database table named trips which has two columns (in addition to others) which both have foreign keys to the locations table. The columns are for a start location and an end location. The problem arises in the trip model in trying to access each location. belongs_to :location, :foreign_key => ''start_location_id'' gives me access to one of the locations but how can
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 May 28
7
Self-referential has_many :through relationship
Hi, I have a self-referential has_many :through relationship setup to track relationships between users. Basically relationships are modeled as a join table with an extra column ''relation''. create table relationships ( user_id integer unsigned not null, friend_id integer unsigned not null, relation char(1) not null, ) --- relations --- f = friend r = request to
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
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,
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.
2005 Dec 27
0
How do I combine :finder_sql and :conditions to perform a sub-search on a custom has_many relationship?
I''m sure there''s something right under my nose that I''m missing. I have two tables with two parallel one-to-many relationships. I wish to use the :finder_sql parameter to essentially ''or'' the two foreign keys. What isn''t working for me is performing a ''sub-search''. Let''s say the tables are "stores" and
2006 May 24
4
AR foreign key problem.
Hello Railslist, (I''m using RadRails 0.6.3 on Windows XP with Ruby 1.8.4, Rails 1.1 and SQLite3) I have two tables in the database: "locations" and "customers": customers.sql --- id INT PRIMARY KEY name VARCHAR 255 address VARCHAR 255 postal_code VARCHAR 255 city VARCHAR 255 --- locations.sql --- id INT PRIMARY KEY postal_code TEXT longitude FLOAT latitude FLOAT
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 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 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 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 19
0
Help with nested HABTM relationship
Hi, I am trying to perform a query with ActiveRecord that I want to put into a Rails application later. For now I just wrote it within a plain old Ruby script for easier testing. I am working with an existing database so I had to map some foreign keys myself. As you can see from the models below, the database has a structure of Prospectlists <=habtm=> Contacts <=habtm=> Accounts