search for: has_and_belong_to_many

Displaying 7 results from an estimated 7 matches for "has_and_belong_to_many".

2009 Feb 23
1
ActiveRecord::AssociationTypeMismatch
I have 2 models: mop, has_and_belong_to_many :contacts contact, has_and_belong_to_many :mops when I save my mop Ii have the users coming in a an array: ["9",10"] I am doing this to asscociate each one to a mop: @contacts.each do |contact| @mop.contacts << contact end Contact(#44950470) expected, got String(#208374...
2012 Feb 14
4
What I'm doing wrong, has_and_belong_to_many
Hello, I''m trying to insert into my migrate but when I try on rails console this error shows: 1.9.3-p0 :001 > group = Group.new => #<Group id: nil, name: nil, description: nil, created_at: nil, updated_at: nil> 1.9.3-p0 :002 > group.name = "Group Name" => "Group Name" 1.9.3-p0 :003 > group.description = "Description" =>
2011 Feb 07
2
Search HABTM relationship in ActiveRecord
Consider the following scenario: Book has_and_belong_to_many Category. In other words, a category may have a lot of books, and a book can have more than one category. What is the best practice to query all books related to some specified categories. For example, if I have following books "From Java To Ruby" - Category: Java, Ruby "Ruby Progr...
2006 Aug 02
2
many-to-one relationship, do I need a second table?
...ame VARCHAR(255), created_at DATETIME, updated_at DATETIME, location_id INT UNSIGNED, FOREIGN KEY (location_id) REFERENCES locations(id), PRIMARY KEY (id) ) TYPE=''InnoDB''; And so, to describe my question, Im wondering if I need the secondary relationship table (like a has_and_belong_to_many relationship) in order to search for people by location. CREATE TABLE `locations_people` ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, location_id INT UNSIGNED, person_id INT UNSIGNED, FOREIGN KEY (location_id) REFERENCES locations(id), FOREIGN KEY (person_id) REFERENCES people(id), PRIM...
2006 Apr 24
9
Confusion with expressing many to many relationship
Hi folks, I am in the process of converting an existing non-rails application to rails, and am not sure what the best approach would be for specifying the relationship between the two sets of data. I''ll describe the existing table structures first. Table 1: Urls Each url has a unique id and two lists of Phrases, these are currently setup as varchars with "," delimitation -
2006 Jan 15
0
HABTM relationships and retrieving multiple selects in controller
Hello all, I have a product table and an option table that are connected to one another via a join table. These two tables both contain has_and_belong_to_many relationships with each other. I am trying to setup a page where I will create a product and add in its options. I have already populated the options table with data to draw from. so, to start, here is the method from my controller: def new @product = Product.new() @opt = Option.find_all end...
2006 Mar 26
3
Making a custom selection form - newbie
...n a web application for my dad''s website; it''s a simple content manager for "listings." Using the scaffolding and other stuff I''ve learned I was able to set up the basic system easily, but the categories are not so simple. Categories are a model: they habtm (has_and_belong_to_many) listings, and listings habtm categories. This way an individual listing can display its categories, and a category can display its listings. Categories are also trees: each major category contains a variety of sub-categories. The difficult part is creating the UI to create a listing: a listin...