Displaying 20 results from an estimated 397 matches for "foreign_key".
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 doesn''t work and I only receive the
associated record''s...
2009 Sep 28
5
Multi-databases support
...order to find a good answer for the "foreign
key problem" which forces OVirt to stay on pg. I have found a plugin on
this particular problem, named foreigner :
http://github.com/matthuhiggins/foreigner
It provides a rails' syntax to common operation on them. For instance :
add_foreign_key(from_table, to_table, options)
remove_foreign_key(from_table, options)
foreign_keys(table_name)
I really like to keep my development computer to run as fast as possible
(ie without a database service), so I have even tried to integrate this
plugin into OVirt, in a transparent way for exist...
2006 Mar 15
1
Through method problems with custom foreign_keys
...ranch_id AND
contacts.p
erson_person_id = 1)
Notice that "contacts.company_branch_id" does not exist, it should be
"contacts.com_branch_id"
Here are the models:
class Person < ActiveRecord::Base
set_primary_key "person_id"
has_many :contacts,
:foreign_key=>"person_person_id",
:class_name=>"Contact"
has_many :company_branches,
:through=>:contacts,
:foreign_key=>"com_branch_id"
end
class CompanyBranch < ActiveRecord::Base
set_primary_key "branch_id"
b...
2006 Mar 31
3
Complex Through Statement
...on their relationship. For example, the Employee may be the
enrollment contact for one merchant and the support contact for another.
Therefore, my Employee class looks like this:
class Employee < ActiveRecord::Base
has_many :enrollment_merchants, :class_name => "Merchant",
:foreign_key => :enrollment_employee_id
has_many :support_merchants, :class_name => "Merchant", :foreign_key
=> :support_employee_id
end
And my Merchant class looks like this:
class Merchant < ActiveRecord::Base
belongs_to :enrollment_employee, :class_name => "Employee&quo...
2011 Jan 15
3
has_many :through with Single Table inheritance
...nt''"
end
class Student < User
has_many :relationships
has_many :parents,
:through => :relationships,
:conditions => "related_as = ''child''"
end
class Relationship < ActiveRecord::Base
belongs_to :parent, :foreign_key => :user_id
belongs_to :student, :foreign_key => :user_id
end
class CreateRelationships < ActiveRecord::Migration
def self.up
create_table :relationships do |t|
t.integer :user_id, :null => false
t.integer :related_user_id, :null => false
t...
2006 Jun 27
3
belongs_to <parent name>, :foreign_key modifier not working
All,
I have two ActiveRecord objects.
TargetList has_many Targets
Targets belongs_to TargetList
I''ve specified
belongs_to :target_list,
:foreign_key => ''DataSetID''
Queries generated by various methods in target_list do not seem to see
the
foreign_key name and keep trying to query my Target table using
"target_list_id" (the default foreign key).
Anyone seen this before?
Wes
--
Posted via http://www.ruby-foru...
2006 Nov 02
4
Still Having Problems With :through When Going To Same Table... Help... please :-(
...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, :class_name => "User", :foreign_key => "user_id"
belongs_to :spankee, :class_name => "User", :foreign_key => "spanked_user_id"
end
db_table:spanks
id | user_id | spanked_user_id | created_at | updated_at
>>>>>
I want to be able to make statemets like:
john = User.find_by_nic...
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 => ''model_name''
Should this work? I''m thinking that the foreign_key and assoc. foreign
key are no longer necessary since Rails c...
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
2005 Dec 22
3
foreign_key setting ignored
...any
linked records in the ''contact'' table. Iv''e used ''generate scaffold'' on
these tables and everything is fine. I then decided to define the
relationship in the relevant model classes...
class Contact < ActiveRecord::Base
belongs_to :company,:foreign_key => "companyid"
end
----
class Company < ActiveRecord::Base
has_many :contact
end
And then I''ve added the following line to views/company/show.rhtml to
try and get at the child elements...
<%= debug(@company.contact) %>
I''ve tried loads of variations o...
2006 Jul 07
3
Newbie Model question (HABTM?)
...ssociated 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 the bill. For another project it is possible the
arrangement is reverse.
I''m guessing this is a HABTM situation, but how do I do the
:foreign_key and :class_name setup.
Greg
--
Greg Freemyer
The Norcross Group
Forensics for the 21st Century
2006 Aug 02
2
Self-Referential has_many :through
...ls. Person and
Relationship. A person has many contacts (Which is another person)
through relationships
class Person < ActiveRecord::Base
has_many :relationship
has_many :contacts, :through => :relationship end
end
class Relationship < ActiveRecord::Base
belongs_to :person, :foreign_key => "person_id"
belongs_to :contact, :foreign_key => "contact_id", :class_name =>
"Person"
end
If I use the code as above then while the relationships appear in the
view the only "Contact" that appears is the Person I am currently
looking at (...
2006 Mar 29
3
Self-referential many-many joins with :through
...http://dev.rubyonrails.org/changeset/4022 that fixed them only went
through 5 days ago..
Cheers
-henster
***********************************************************************************
class Topic < ActiveRecord::Base
has_many :item_collection, :class_name => "Grouping", :foreign_key
=> "item_id"
has_many :group_collection, :class_name => "Grouping",
:foreign_key => "group_id"
has_many :groups, :through => :group_colletion
has_many :items, :through => :item_collection
end
**************************************************...
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 Apr 07
4
STI and foreign_key problem
...formation than an initial case (I
realize I could just set a flag to separate them, but there is a good
reason to separate them), but both need to be related to the children
table. Here is the model code:
class Case < ActiveRecord::Base
end
class Registered < Case
has_many :children, :foreign_key => "case_id"
end
class Initial < Case
has_many :children, :foreign_key => "case_id"
end
class Child < ActiveRecord::Base
belongs_to :initial
belongs_to :registered
end
When I attempt to access the children attribute via an Initial object I
get an unknown...
2006 Feb 27
4
2 belongs_to to the same parent table
...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 :buddies, :foreign_key => ''user_id''
#has_many :buddies, :foreign_key => ''user_buddy_id'' # does not work, if
added as last, the previous relationship on buddies drops
end
class Buddy
belongs_to :user, :foreign_key => ''user_id''
#belongs_to :user, :foreign...
2006 Jan 09
3
Include with two references of one model of the same table
...ed only one select on "matches" where I think should be two
selects on two aliases of "matches".
Heres some code below to better understand what I''m talking about.
class Match < ActiveRecord::Base
belongs_to :hometeam, :class_name => "TeamsSeason", :foreign_key =>
"hometeam_id"
belongs_to :awayteam, :class_name => "TeamsSeason", :foreign_key =>
"awayteam_id"
end
class TeamsSeason < ActiveRecord::Base
has_many :hometeam, :class_name => "Match", :foreign_key =>
"hometeam_id", :depe...
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
2010 Nov 09
2
Undefined method
I am very new to ROR. (Ruby 1.8.7, rails 2.1.1, rack
0.8.7, mysql 5.1.41)
I has my_app/lib/migration_helpers.rb file:
module MigrationHelpers
def self.foreign_key(from_table, from_column, to_table)
constraint_name = "fk_#{from_table}_#{to_table}"
execute %{alter table #{from_table}
add constraint #{constraint_name}
foreign key (#{from_column})
references #{to_table}(id)
}....
end
In my_app/db/migrate/001_cr...
2008 Jul 04
4
Libs directory
Hello,
I had an application on Rails 1.2 or 1.1 (don''t remember). Now I have
updated it to 2.1.
I had a migrations_helper.rb in the Libs directory which defined
foreign_key and drop_foreign_key methods. But now migrate task doesn''t
find them. Have I to include this directory somewhere with Rails 2.1?
Doesn''t it work as always?
Could I use another thing to declare foreign keys without having a
class made by myself?
--~--~---------~--~----~-----------...