similar to: HABTM relationship

Displaying 20 results from an estimated 10000 matches similar to: "HABTM relationship"

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
2008 Dec 16
1
Callback when objects connect as a habtm relationship
If Product and Category models are in a habtm relationship, i.e. class Product < ActiveRecord::Base has_and_belongs_to_many :categories end class Category < ActiveRecord::Base has_and_belongs_to_many :products end I want a piece of code to be executed every time a product is connected to a category. Where do I put this code? Which callback (and on which model) will be triggered? Any
2006 Jan 19
5
Multiple HABTM relationships with self ???
I need to have a table related to itself via a join table. Will HABTM support this? That is: class Recipe < ActiveRecord::Base has_and_belongs_to_many :recipes, :join_table => "recipes_recipes" end More importantly -- how does RoR support MULTIPLE self-joins? I.e., to relate the table to itself via multiple join tables. SFAIK, HABTM won''t support multiple
2006 May 12
2
How to declare several HABTM-relationships?
Hello, Is it possible to have several HABTM-relationships for the same object? Example: Imagine I have 3 objects (classroom, student, teacher) and define the associations for the student as: class Student < ActiveRecord::Base has_and_belongs_to_many :classrooms has_and_belongs_to_many :teachers class Classroom < ActiveRecord::Base has_and_belongs_to_many :students class Teacher <
2006 Jun 30
2
how to HABTM with STI ??
Hello all This is my first post so excuse the basic question. (and any repeats I just got an email saying this post was too big so I have re-submitted a smaller version) I was following the thread on http://lists.rubyonrails.org/pipermail/rails/2006-May/038988.html regarding the STI on HABTM for RoR. I have a very similar problem and was hoping for some help. I have the
2006 Feb 20
0
No Magic for HABTM forms?
Hi, I posted yesterday asking how to get form tags to reference the associated objects in a habtm relationship. I was hoping for Rails Magic, but it looks like Rails doesn''t have habtm magic beyond a certain point. Here was my solution for others who might have the problem. Also, I hope someone shows me that there is a simpler way. The Database Model: class Registration <
2006 Nov 08
0
Prevent an object from being destroyed in HABTM relationship
Hello all, I have the following models: class Sku < ActiveRecord::Base has_and_belongs_to_many :options end class Option < ActiveRecord::Base has_and_belongs_to_many :skus end By default if I destroy an Option any relationships between Options and Skus will be removed as well. But, I want to prevent an Option from being destroyed when it is associated with a Sku in the options_skus
2006 Feb 14
1
Another HABTM Question
Hi there, I have a question on what would be the best way to save a HABTM model. A posting habtm categories, and a category habtm postings. class Category < ActiveRecord::Base has_and_belongs_to_many :postings end class Posting < ActiveRecord::Base has_and_belongs_to_many :categories end In my blog_controller, where the actual posting is saved, is where I think I''m
2006 Nov 14
3
messed-up habtm relationship
Hi, I have a many-to-many relationship between dishes and ingredients class Dish < ActiveRecord::Base has_and_belongs_to_many :ingredients end class Ingredient < ActiveRecord::Base has_and_belongs_to_many :dishes end I have a join table dishes_ingredients now when i access my_dish.ingredients, i get a list of what looks like Ingredient objects, but the but they don''t have
2006 Jun 05
7
Is HABTM Dying?
For a while, I''ve been getting that HMT is replacing HABTM. It appears that HMT can do all of what HABTM can do and more. The question is: Should I stop using HABTM? Let''s take a simple case: A case has many categories For a given category, there are certain valid statuses Category has_and_belongs_to_many :statuses Status has_and_belongs_to_many :categories Question: Is
2006 Jan 03
0
habtm and insert_sql
Briefly, I want to create an :insert_sql attribute for a has_and_belongs_to_many relationship, and then add items to that relationship using push_with_attributes. Is that possible? Less briefly: I have a legacy postgresql database where one of the join tables has an ID column, so I had to set up the association with a custom :finder_sql attribute, as follows: class Topic <
2006 Mar 13
3
HABTM: two habtm''s between the same two tables
Imagine I want to track people, and the clubs that they belong to. table people with columns person_id, person_name table clubs with columns club_id, club_name And I have the association table: table clubs_people with columns person_id, club_id Now I know how to do this habtm between the two, in order to associate people with clubs that they belong to. However my application also needs a
2009 Oct 04
1
circular relationship - habtm
So I have 2 models: Picture and Comment. Pictures have many Comments, but I''d like for users to be able to post Pictures in Comments, so Comments will have one Picture (possibly). This creates a kind of circular relationship it looks like, and the only way I could think of to implement this is with has_and_belongs_to_many. Am I right, or is there a better way to do this?
2005 Dec 15
2
HABTM being tricky
I''ve just been bodyslammed by a problem with has_and_belongs_to_many - as far as I can tell, if it doesn''t appear at the top of other relationship definitions it doesn''t seem to work right. For example: class Artist < ActiveRecord::Base has_and_belongs_to_many :genres has_many :albums has_many :videos has_many :cds has_many :collections end ..works fine
2006 Mar 25
1
Nuby: HABTM and drag-and-drop views
I have two tables that have a HABTM relationship: Teacher has_and_belongs_to_many Groups, and Group has_and_belongs_to_many Teachers. This is what I want: select a Teacher, and then drag Groups from one box to another to assign them to the teacher. Or, select a group, and drag and drop Teachers to assign them to groups. All using AJAX, (off course). Only problem is, I don''t know
2007 Jul 26
1
Bi-directional self-referential HABTM
Hi, I''m having a little trouble figuring out how to make 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 =>
2006 Feb 19
4
Multiple HABTM to one table
I have a class Player, and a class Game. Game has two HABTM relationships to the Player table through seperate relationship tables. class Game < ActiveRecord::Base has_and_belongs_to_many :players, :uniq => true has_and_belongs_to_many :victors, :class_name => ''Player'', :uniq => true end When I add Player A to players, and Player B to victors, and save the
2006 Jun 20
1
Preventing Dups in HABTM
I have a habtm that looks like: report has_and_belongs_to_many :subscribers subscriber has_and_belongs_to_many :reports When I add a report to a subscriber, I have to run code like: raise "already there, idiot!" unless report.subscribers.find_by_id(subscriber_id).nil? Is there a better way to avoid adding duplicative associations? has_many :through seems like overkill for this
2006 Aug 09
3
HABTM and getting to arrays from either direction
I didn''t find exactly an answer on this one, so I''d like to get a clarification from folks who live & breathe HABTM. class foo has_and_belongs_to_many :bars end class bar has_and_belongs_to_many :foos end (and yes, I have a bars_foos table in my db) def test_habtm bar = Bar.new foo = Foo.new foo.bars<<bar assert !foo.bars.empty? assert
2005 Jun 03
1
sorting on a habtm relationship
I have two tables ("products" and "categories") that have a has_and_belongs_to_many relationship, and I need to be able to arbitrarily sort products in the scope of a category using something like acts_as_list. Problem is, since each product can belong to multiple categories, it doesn''t work to use acts_as_list and have the "position" field be in the