Displaying 3 results from an estimated 3 matches for "posts_count".
2006 Jun 08
2
Activerecord Update syntax.
This what I have - sadly, it does not work :( .
posts = {params[:topic][:forum_id] => { "posts_count" => "posts_count +
@topic.posts_count"}, @topic.forum_id => { "posts_count" => "posts_count
- @topic.posts_count" } }
Forum.update(posts.keys, posts.values)
It''s suppose to subtract the posts_count from topic, and add it and
subtract it from po...
2007 May 14
3
Counter Problem
...dels
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, :integer, :default => 0
for Forum and Topic
- Now a simple action
def some_action
@post = Post.new(params[:id])
@forum.posts << @post # The @forums.posts_count is up by 1
@topic.posts << @post # The @topic.posts_count is _not_ up by 1
end
Both, the forum_id and topic...
2006 Jun 21
6
Sort table by child row property?
I''m building a simple forum system which features a topics and a posts
table. The topic model has a has_many association with the post model,
i.e.:
class Topic < ActiveRecord::Base {
has_many :posts
}
class Post < ActiveRecord:Base {
belongs_to :topic, :dependent => true
}
Now, I wish to sort the topics by the created_at property of the last
post, but I can''t