Displaying 20 results from an estimated 100000 matches similar to: "HABTM / Counter Cache"
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 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 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
2007 Aug 21
2
counter cache
Hi,
I have two models, employees and departments, and i am using
counter_cache to count the number of employees in a department.
This works great, but employees can change their departments, and the
counter cache does not get updated to reflect this.
Is their a built in way to do this, or do i have to implement my own
before_save hook
thanks
--~--~---------~--~----~------------~-------~--~----~
2007 Sep 12
1
Counter cache like plugin for sum
Hi list,
Is there a plugin similar to counter_cache except for caching sums
instead of counts? The reason I ask is for performance and convenience
for reporting.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to
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,
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 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 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 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:
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
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
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 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 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 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
2007 May 14
3
Counter Problem
Hi. I have a problem with counters in Rails. The situation looks like
this:
-3 simple models
class Forum < ActiveRecord::Base
has_many :posts
end
class Topic < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :topic, :counter_cache => true
belongs_to :forum, :counter_cache => true
end
- In migrations i have declared
t.column :posts_count,