similar to: Using through with habtm

Displaying 20 results from an estimated 9000 matches similar to: "Using through with habtm"

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 Feb 07
1
habtm :uniq causing duplicate inserts? How to update Rails?
Hello *Gem* experts, Sorry for asking multiple questions in one post but they are both related to one problem. So far I have the following code: class Member < ActiveRecord::Base has_and_belongs_to_many :blogs, :uniq=>true ..... end class Blog < ActiveRecord::Base has_and_belongs_to_many :members, :uniq=>true ... end The issue is that
2006 Feb 01
0
habtm and counter (xxx_count field in DB)
Hi all I have the following models: class Member < ActiveRecord::Base # DJ Profiles the member is part of has_and_belongs_to_many :disc_jockeys, :join_table => ''members_are_disc_jockeys'', :uniq => true end class DiscJockey < ActiveRecord::Base # Members that are part of this DJ profile
2006 Jun 14
3
Prevent duplicate HABTM associations
Hi, I am trying to restrict duplicate has_and_belongs_to_many associations. I tried to find support for a association validation for duplicates but couldn''t find anything. I understand I could use :uniq=>true on the model association but this would only prevent it from displaying duplicates, I want to stop duplicate associations being inserted in the first place. I have a vague
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
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 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 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
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 18
3
Model Madness: habtm vs through
This has me scratching my head: a Person has many Things a Person has many Collections a Collection has many Things ...Things in a Collection are ordered ...Things in a Collection can be related to (created by) any User ...a collection has additional attributes, such as a name etc I am confused about habtm in rails (especially when using acts_as_habtm_list) vs. going the :through route.
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 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 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
2007 Oct 15
0
converting from HABTM to has_many :through
Hello, I have a has_and_belongs_to_many relationship that I''ve realized I need to add additional attributes to. So I''m converting it to a has_many :through (HMT) relationship. This is the first time I''ve used an HMT, and it seems like I''m using too much code. I couldn''t figure out how to get the join model objects to update automatically as a result of
2006 Feb 28
8
HABTM count table
Hello, I have a question about HABTM and counting records. I have these models class Sort < ActiveRecord::Base has_and_belongs_to_many :reports end class Report < ActiveRecord::Base has_and_belongs_to_many :region has_and_belongs_to_many :subjects has_and_belongs_to_many :sorts end And i would like to get a count like @sort.reports.count The problem is get this query:
2011 Jan 14
0
[Rail3] How to construct full-text search for habtm associations
hi all, i''m new to this group and currently using Rails 3.0.3 and meta_where 0.9.10. i''m considering how to make a full-text searching feature to my project, and my models, for example, should be defined like below: class Group < ActiveRecord::Base has_and_belongs_to_many :users # :title (string) end class Comment < ActiveRecord::Base has_and_belongs_to_many :users
2011 Apr 16
0
adding HABTM association while creating a record
Hello Experts, I have a HABTM association as followed: class Account < ActiveRecord::Base has_and_belongs_to_many :user end class User < ActiveRecord::Base has_and_belongs_to_many :type has_and_belongs_to_many :account end class Type < ActiveRecord::Base has_and_belongs_to_many :user end I have the following query; I Have a parent user who is creating another user under its
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
2010 Jan 20
0
need help with nested forms and habtm
Hi, I''m currently stuck with a problem I just can''t find a clever solution for. I checked every tutorial, issuetracker, API reference I could find but found nothing to "enlighten" me --> I desperately need your help :-). My Question is: is it possible to use nested forms for habtm associations? --> Here some more info about what I wanted to do and what failed