Displaying 20 results from an estimated 397 matches for "foreign_keys".
Did you mean:
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
2009 Sep 28
5
Multi-databases support
...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 existing db.
After a couple of patch on the plugin itself and some hack on
migrations, it see...
2006 Mar 15
1
Through method problems with custom foreign_keys
A person has a many company_branches and
A company_branch has many people.
This join is represented using a "contacts" table.
I am using a legacy schema so i am forced into using non-standard rails
primary keys. I am using the new through relationship in rails 1.1.
p=Person.find(1)
b=p.company_branches # gives this error:
ActiveRecord::StatementInvalid: OCIError: ORA-00904:
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
2011 Jan 15
3
has_many :through with Single Table inheritance
I have the following model structure setup.
class User < ActiveRecord::Base
end
class Parent < User
has_many :relationships
has_many :children,
:class_name => "Student",
:through => :relationships,
:conditions => "related_as = ''parent''"
end
class Student < User
has_many :relationships
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
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 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 =>
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
I''m having a spot of bother creating a ''has_many'' relationship between
two legacy database tables. The relationship is ''company'' table has many
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
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 Aug 02
2
Self-Referential has_many :through
Hello all.
I am trying to create a self-referential has_many :through. I used the
following site as a guide
http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through
but it still doesn''t appear to be working. I have two models. Person and
Relationship. A person has many contacts (Which is another person)
through relationships
class Person < ActiveRecord::Base
2006 Mar 29
3
Self-referential many-many joins with :through
I thought I had this nailed but.. now I''m seeing spots..
I''ve included my models below, feel free to ignore them. I''m really
just after an example that works. I couldnt find one on the wiki...
which is fair enough considering Ricks patch:
http://dev.rubyonrails.org/changeset/4022 that fixed them only went
through 5 days ago..
Cheers
-henster
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
Hi,
I am trying to use STI since my classes only vary by one column in the
database.
Here is the structure (names have been changed to protect the innocent):
Case
/ \
Registered Initial
\ /
Children
A registered case has additional information than an initial case (I
realize I could just set a flag to separate them, but there is a good
reason to separate
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
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 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})
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