similar to: HABTM: Find sorted by number of associations

Displaying 20 results from an estimated 4000 matches similar to: "HABTM: Find sorted by number of associations"

2006 May 22
3
STI, HABTM & counter_cache
Hello world... I have an interesting issue that the online docs aren''t helping me with. In my app I have 4 models Item < ActiveRecord Deal < Item Product < Item Category < ActiveRecord Item has_and_belongs_to_many :categories... On each category record I''d like to maintain a product_count and deal_count to increase performance. This doesn''t appear
2006 Mar 11
1
HABTM 1.1 - counter cache?
Just wondering - will HABTM (or thru or whatever it''s called) in Rails 1.1 have a counter_cache, similar to belongs_to? Joe -- Posted via http://www.ruby-forum.com/.
2006 Apr 05
5
Updating attributes in HABTM association
Hi, I am trying to find a way tp update attributes in a habtm association. I am trying to use the code from ticket #2462, but as my association_class_primary_key_name seems to be empty the generated sql code is corrupt. I hope thats not a problem of my model that this variable is empty. What would you recommend to update those attributes (rails 1.1) THANKS!!! -- Posted via
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 Jul 10
18
Deleting join association of has_many :through
I''m trying to use has_many :through, since my join model deserves being more than just an intersection table. But when I try to break the association, the break only seems "temporary": Let''s say my two tables are Users and Colors, and the join model is Favorites. user = Users.find(1) user.colors.length >> 2 c = user.colors.first >> #<Color:....>
2006 Jul 10
7
What is has_many :through really buying you over HABTM?
So having just learned how to do has_many :through as opposed to HABTM, and then, being concerned that I wouldn''t get it to work, I started thinking about these two approaches. It seems to me that the _only_ problem that the HM:T (has_many :through) approach solves that HABTM doesn''t is the issue of the potential collision of id columns between your join table and one of
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 May 31
6
habtm on an array (or object.habtm.habtm)
Hi, I have three Models: User, Group and File. User habtm groups and Group habtm Files How can I find all files that a particular user has access to? eg user.groups.files ? As user.groups returns an array, the above doesn''t work. Id like to find the files for all groups in that array, without adding any code to the User model. Thanks in advance PS I just posted this in the
2006 Jul 05
7
HABTM join table has an "ID" column - is this an issue?
All, I''m building model objects for existing tables that I cannot modify. In AWDWR, Dave says "Note that our join table has no id column...The second reason for not including an id column in the join table is that AR automatically includes all columns from the join tables when accessing rows using it. If the join table included a column called id, its id would overwrite the id
2006 May 01
4
Find rows with associations in habtm
This may have been asked/answered before - if so, i apologise... I have the following table layout in a habtm relationship: ------------ ----------------------- -------------- | products | ----| categories_products |-----| categories | ------------ ----------------------- -------------- What would be the best way to pull out all the products for a given category? At the
2006 Jun 01
3
Newbie: HABTM problems
I''m new to RoR and trying to make a HABTM relationship work. I have no problems with displaying the fields (after I pumped the data into MySQL manually outside of RoR), but when I try to edit a record, it =does= save the changes in the primary record, but =not= the join table. When I look in the development log, I see the update to the main table, but nothing about the join
2006 May 23
2
HABTM for Dummies Question
Taking time off from programming is always painful :-). I have the following Models: ==== class Tag < ActiveRecord::Base has_and_belongs_to_many :problems end class Problem < ActiveRecord::Base belongs_to :user has_and_belongs_to_many :tags end ==== And the following migrations: ==== create_table "problems" do |t| t.column "user_id", :integer
2006 Jul 05
1
created_on in HABTM table getting parent dates
All of my HABTM tables receive the parent created_on/last_update_on dates whenever a record is inserted into these join tables. I don''t have any defaults in the database or anything else populating these tables. I assumed rails would populate these automagically. Is there something that needs to be done to get this to populate with the correct current timestamp instead of
2006 Mar 22
2
habtm vs. has_many/belongs_to
In AWDWR David says (pg 232), "When a Join Wants to Be a Model: While a many-to-many relation with attributes can often seem like the obvious choice, it?s often a mirage for a missing domain model. When it is, it can be advantageous to convert this relationship into a real model and decorate it with a richer set of behavior. This lets you accompany the data with methods. As an example,
2006 Mar 28
3
Rails 1.1: Is HABTM obsolete?
Does the new has_many :through and belongs_to :through obsolete (well, replace and essentially deprecate) has_and_belongs_to_many? Joe -- Posted via http://www.ruby-forum.com/.
2006 Jul 10
4
HABTM vs. using has_many :through
All, I''ve heard recently about has_many :through as a necessary alternative to HABTM (when the join table has it''s own id column, say, in a legacy schema). However, is the prevailing Rails wisdom now that one should use has_many :through in _all_ cases? If so, why? Thanks, Wes -- Posted via http://www.ruby-forum.com/.
2006 Jun 05
5
adding habtm through migrations
Hello, I''m stuck, I''ve got a model Product and would like to add a new model called Category. Furthermore, I want to set up a many2many relationship between the mentioned models. the problem is that I do not know how to set the primary key in the categories_products table. this is what I''ve got in my migration file: create_table :categories do |t| t.column :name,
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
2006 Jan 06
6
HABTM problem not saving all associations
Hello all, I have an Order object that has and belongs to many Products and has and belongs to many Loan Types. This is so I can select multiples of each in my order entry screen via checkbox groups. I''m having some trouble with saving multiple HABTM associations for a single model object; only the first HABTM association declared in the model will save during the initial @order.save
2006 Jul 12
1
odd habtm behavior? or is it me?
Hello List, I''m a bit spent on this problem, and my code might be whack. I seem to be encountering a problem where the primary key on a join table is not being resolved correctly. I will elaborate after some code bits. I am creating the join table using migrations, and relevant model code is this: class Post < ActiveRecord::Base has_and_belongs_to_many :records