similar to: HABTM 1.1 - counter cache?

Displaying 20 results from an estimated 30000 matches similar to: "HABTM 1.1 - counter cache?"

2006 Apr 30
2
HABTM: Find sorted by number of associations
Hi, I''ve been googling and searching the forums for some time but can''t seem to find exactly what I''m looking for. Suppose User HABTM Products (for example a favorites list). I would like to construct a single query for finding Products ordered by the number of Users that have flagged them as favorites. Although I can construct the query using SQL a with a
2008 Jun 03
1
Custom counter cache
class Category has_many :tracks end class Track belongs_to :category, :counter_cache => true named_scope :converted, :conditions => {:converted => true} named_scope :active, :conditions => {:active => true} end I want to make custom counters for scoped associations, e.g: category.converted_tracks_count category.active_tracks_count And when `track` changes its converted,
2006 Jan 20
11
HABTM relations
Hi, I have 3 tables with HABTM relation. USERS -> QUOTE_TO_USER <- QUOTES Table QUOTE_TO_USER has 3 attributes: quote_id, user_id, component. I have a form where I can tie multiple users to QUOTE. This is easy one, thru "user_ids" (@quote[:user_ids] = @params[:quote][:user_ids]). In this form I have all users and I just check those I want to tie to this quote, however
2006 Jul 11
1
counter_cache, has_many and belongs_to
I am a bit confused about counter_cache here. The API docs http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html say that only the belongs_to association can take the :counter_cache option. When I try to use it on a has_many I get an "unknown key(s): counter_cache" error. Why would this be the case? belongs_to means that this model has a field with an id
2006 Mar 24
6
Should counter_cache fields be saved in the database?
As far as I can tell, the counter_cache option on a belongs_to model doesn''t actually save anything in the database. For example, I have the following models: class Parent < ActiveRecord::Base has_many :children, :conditions => "deleted_at IS NULL" end class Child < ActiveRecord::Base belongs_to :parent, :counter_cache => true end With the following
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 16
1
HABTM -VS- belongs_to/has_many, for self-referential joins
Ok, David says on page 241 that sometimes a many-to-many relation with attributes are better implemented as an actual model instead of using HABTM. Well, I''ve got that situation and I can''t figure it out. All of the examples in the book have HABTM examples between 2 different tables, but I want to have a HABTM relation on 1 table with itself. (e.g., if I have a table Things,
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 Apr 26
2
HABTM with ajax_scaffold
has anyone managed to do this? It works great for has_one, belongs_to type stuff, but i cant seem to get a HABTM setup going. Any demo code or advice greatly appreciated. Excellent work on this tool by the way its really great work. adam -------------- next part -------------- An HTML attachment was scrubbed... URL:
2006 Apr 18
1
habtm and belongs_to one table
I have the following: Posts belong to a User Posts may be Monitored by many Users How do you characterize this? class Post < ActiveRecord::Base belongs_to :user has_many :monitors class Monitor < ActiveRecord::Base has_many :posts, :as => user class User < ActiveRecord::Base has_many :posts # when a user *does* a post belongs_to :monitor, :polymorphic => true --
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 Jan 02
0
HABTM / Counter Cache
All, Is it possible to use counter_cache w/ has_and_belongs_to_many? Thanks, EJC
2006 Jul 07
3
Newbie Model question (HABTM?)
All, If I have a table that has several discrete fields that all point to the same associated field, how do I model it. Specifically, If I have a project table that has 2 fields: specifying_company, and responsible_company. And one table of associated companies, how do I do the :belongs_to / :has_many stuff ie. For a given project company A may be writing the spec, but company B may be paying
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 Mar 18
4
Accessing overridden method
I have two model classes: class Item < ActiveRecord::Base belongs_to :channel, :counter_cache => true validates_presence_of :channel end class Channel < ActiveRecord::Base has_many :items, :dependent => true end In the Channel controller I have variable channel.items, an Array of Items. I would like to use the Array find method. However, channel.items.find() is a Rails
2010 Aug 18
6
Once I added this HABTM, one of my 'through' relationships, on a non-habtm model, seems to have broke?
I''m a rails newb and have been Googling about this, but I''m still stumped. Not showing everything here, but basically it should be a pretty common setup so I''m sure others know what I''m doing wrong. - A meter can belong to many meter_groups - A meter_group can have many meters. - A user can ''subscribe'' to viewing a meter_group (Subscription)
2005 Nov 16
1
HABTM: deleting records based on attributes
Hello All, I am new to ROR, and can''t seem to get HABTM to cooperate entirely... however I might be abusing it! Before I try a different strategy I thought I''d ask here and see if I''m missing something simple. So say Projects and Companies are related. Projects can have multiple Companies, and Companies can be on multiple Projects. But, the same Company can also
2005 Dec 15
1
migration: counter cache & "reset_column_information"
To speed up <%= @project.members_count %> , I added a counter cache to the ''projects'' table with the migration below: def self.up add_column "projects", "members_count", :string, :default => "0" Project.reset_column_information Project.find(:all).each do |p| p.update_attribute :members_count , p.members.count
2006 May 17
2
Association data clobbering (foreign keys too?)
Can someone please confirm or correct the following statements? If I have the following tables create table as (id int, [...], b_id int); create table bs (id int, [...], a_id int); create table as_bs (a_id int, b_id int); and the associations woould be defined like this class A << ... habtm :bs belongs_to :b end so my Model A has a habtm collection of Bs *plus* a direct
2006 May 17
10
HABTM << producing incorrect insert sql ?
Greetings railsers - I''m trying to add to a collection through HABTM, but the sql insert is trying to insert a PK rather than letting mysql produce the auto_increment''ed PK. ## @medication_dose holds a validated, saved model @medication_dose.medication_frequencies << MedicationFrequency.find (:all) The above bails with, Mysql::Error: #23000Duplicate