search for: association_foreign_key

Displaying 20 results from an estimated 53 matches for "association_foreign_key".

2006 Feb 21
3
HABTM :insert_sql help
...getting the error: ''undefined local variable or method `record'' for Project:Class'' has_and_belongs_to_many :people, :class => ''Person'', :join_table => ''ProjectTeamRole'', :foreign_key => ''ProjectID'', :association_foreign_key => ''PersonID'', :insert_sql => "INSERT INTO ProjectTeamRole(ProjectID,PersonID,TeamRoleID) VALUES(#{id}, #{record.PersonID},1)" I can see that #id refers to the current Project object, but how do I refer to the PersonID that will be inserted if not as above?? t...
2007 Sep 06
4
HABTM association with own class?
If I have a class, Asset, which has and belongs to many associated Asset objects, how do I do this? has_and_belongs_to_many :associated_assets, :class => "Asset", :foreign_key => ?????, :association_foreign_key => ????? Right now, my table has a :first_asset_id and a :second_asset_id, but I don''t see how the objects themselves are supposed to distinguish one from the other. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this mess...
2005 Mar 01
0
has_and_belongs_to_many problem
...ete(@creator) rabble from #rubyonrails suggested adding multiple habtm associatings in the Issue object. Here''s how they look: class Issue < ActiveRecord::Base has_and_belongs_to_many :creators has_and_belongs_to_many :writers, :class_name=>''Creator'', :association_foreign_key=>''creator_id'', :conditions=>''creator_job_id=1'' has_and_belongs_to_many :pencillers, :class_name=>''Creator'', :association_foreign_key=>''creator_id'', :conditions=>''creator_job_id=2'' has_a...
2010 Oct 06
2
reflect_on_association method
...veRecord::Base belongs_to :contractor, :class_name => "BusinessUnit" end I expected the reflect_on_association method to return associated_foreign_key "contractor_id" but it returns "business_unit_id": ruby-1.9.2-p0 > Order.reflect_on_association(:contractor).association_foreign_key => "business_unit_id" do I miss something? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from...
2006 Jan 19
0
Help with nested HABTM relationship
...ed. What am I doing wrong? 1 # set up the structures 2 class Prospect_list < ActiveRecord::Base 3 has_and_belongs_to_many :contacts, 4 :join_table => "prospect_lists_prospects", 5 :foreign_key => "prospect_list_id", 6 :association_foreign_key => "related_id" 7 end 8 9 class Account < ActiveRecord::Base 10 has_and_belongs_to_many :contacts, 11 :join_table => "accounts_contacts", 12 :foreign_key => "account_id", 13 :association_foreign_key => "c...
2007 Jul 26
1
Bi-directional self-referential HABTM
...a self- referential HABTM bi-directional. I have a Employee class. Each employee can have a couple of bosses, who are also employees. The employee class has the following HABTM: has_and_belongs_to_many :bosses, :class_name => "Employee", :join_table => "bosses_courses", :association_foreign_key => "boss_id", :foreign_key => "employee_id" Now this works fine.. but only one way. I can get all bosses of an employee but I can''t get all employees of a boss. In hindsight I think it probaby would have been better to use a :through relationship for this, but I...
2007 Jan 03
3
Self-referential habtm with condition is broken
Here''s a simplistic model class. class Person < ActiveRecord::Base has_and_belongs_to_many :relatives, :class_name => ''Person'', :join_table => ''relatives'', :foreign_key => ''from_id'', :association_foreign_key => ''to_id'' has_and_belongs_to_many :brothers, :class_name => ''Person'', :join_table => ''relatives'', :foreign_key => ''from_id'', :association_foreign_key => ''to_id'', :condit...
2005 Mar 08
15
Rails 0.10.1and WEBrick
Doesn''t appear to work with WEBrick. Works find with Apache/FastCGI. Something wrong in the way Rails is trying to process paths from the WEBrick server. If I try to send in http://localhost:3000/recipes/new, WEBrick is interpreting /new as my controller, instead of my action.
2006 Mar 15
3
Self-referential join model does not work
...> #<Node:0xb742e20c @attributes={"body"=>"", "title"=>"From", "id"=>"1"}> Same result even if I change :foreign_key in the Node model from ''node_id'' to ''related_node_id''. Furthermore, :association_foreign_key is not accepted as a parameter to has_many :through associations. Does anybody have a clue of what I am doing wrong here? Or is it that Rails 1.1 does not support self-referential join models? Thanx in advance for the help and consideration, Edoardo "Dado" Marcora
2006 Jun 16
3
Does HABTM support non "id" FKs?
...s this removes the need to join with the 42K record zip_codes table. However, when I do the following in the my model: class ZipCode < Active.... has_and_belongs_to_many :counties, :foreign_key => "zip_code" class County < Active... has_and_belongs_to_many :zip_codes, :association_foreign_key => "zip_code" AR still uses ZipCode.id when I call county.zip_codes << some_zip, instead of ZipCode.zipcode, which is the preferred behavior. Am I doing something wrong or is AR ignoring me? To solve the problem i simply made the ID of the ZipCode equal to the ZipCode, but I...
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 can just go to the join model and figure out the foreign keys, right? We...
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 19
5
Multiple HABTM relationships with self ???
...or the class, and then use the :class_name option to specify those controllers? SOrt of like so: class Recipe < ActiveRecord::Base set_primary_key "R_ID" has_and_belongs_to_many :recipes, :join_table => "recipes_recipes", :foreign_key => "R_ID", :association_foreign_key => "R_ID2" has_and_belongs_to_many :recipes2, :join_table => "recipes_recipes2", :foreign_key => "R_ID", :association_foreign_key => "R_ID2" has_and_belongs_to_many :recipes3, :join_table => "recipes_recipes3", :foreign_k...
2009 Mar 23
2
Select updates database?
...fields which works perfectly. I can provide more information if needed, but I would like the field to work as a dropdown instead of a text field. My Model: has_and_belongs_to_many :industries, :join_table => "grant_loans_industry", :foreign_key => "grant_loans_id", :association_foreign_key => "industry_id" belongs_to :state My Controller: before_filter :login_required layout "admin" active_scaffold :grant_loan do |config| config.list.columns = [:agency, :gov_type, :title, :url] config.columns.exclude :state_name config.label = '...
2008 Aug 29
3
Many to Many Relationship with One Model
Hey everyone, I''m working on allow users to follow other users in my app so they can receive updates to what all their friends are doing (like Facebook/ Twitter). I''m wondering on how the relationship would be for the model. Sounds like a HABTM type of association, but how would I go about doing it for only one model? Thanks, Tony
2006 May 16
4
Problems with multiple ''id'' columns in a join_table
...says :- class Person < ActiveRecord::Base has_and_belongs_to_many :parents, :class_name=>"Person", :join_table=>"relationships", :conditions=>"role = ''parent''", :foreign_key=>"object", :association_foreign_key=>"subject" has_and_belongs_to_many :children, :class_name=>"Person", :join_table=>"relationships", :conditions=>"role = ''parent''", :foreign_key => "subject", :association_fore...
2006 Apr 03
1
has_many :trough with 2x the same table
...this to a has_many :trough. Unfortunately I can''t get it to work.. the documentation on this feature is a bit sparse at the moment. This is my old habtm: has_and_belongs_to_many :friends, :join_table => ''user_friends'', :foreign_key => ''user_id'', :association_foreign_key => ''friend_id'', :class_name => ''Person'' I''ve tried various things, but I''m completely lost now. I looked at the :source option, but that doesn''t allow me to do this and the :class_name parameter doesn''t seem to work eith...
2006 Jan 06
2
Re: Some advice on DB modeling
...#39;friends'', :class_name => ''User'', :foreign_key => ''friend_id'' has_and_belongs_to_many :friends_of, :join_table => ''friends'', :class_name => ''User'', :foreign_key => ''user_id'', :association_foreign_key => ''friend_id'' attr_accessor :new_password attr_accessor :friends attr_accessor :friends_of ... end But when I use user.friends or user.friends_of they always return nil even after I entered some data in the db manually. There are no errors in the logfile... Any...
2005 Aug 19
2
data validation
...model looks like this: class Company < ActiveRecord::Base has_many :contacts, :foreign_key =>''company_id'' has_and_belongs_to_many :categories, :join_table => ''company_to_category'', :foreign_key => ''company_id'', :association_foreign_key => ''category_id'' validates_presence_of :name validates_uniqueness_of :name validates_lenght_of :name, :maximum => "20" ,:message => "too long" end The presence_of and the uniqueness_of work fine, but it doesn''t throw any err...
2005 Oct 05
0
has_and_belongs_to_many on legacy DB
...specify that the association foreign key is studentId, not student_id. Any idea what I''m doing wrong here? Thanks. Student < ActiveRecord::Base set_table_name :student set_primary_key :studentId has_and_belongs_to_many :teachers, :join_table => ''student2teacher'', :association_foreign_key => ''studentId'' end Teacher < ActiveRecord::Base set_table_name :teacher set_primary_key :teacherId has_and_belongs_to_many :students, :join_table => ''student2teacher'', :association_foreign_key => ''teacherId'' end __________________...