similar to: Chaining queries in ActiveRecord

Displaying 20 results from an estimated 200 matches similar to: "Chaining queries in ActiveRecord"

2010 Jan 05
2
Conditional named_scope chaining with params (Need help)
Hello there, I have a model that has more then one named_scope. In my action Index of the controller that handle this model I want to do this in a drier way: if params[:ownership] == "mine" @posts = Post.tagged_with(params[:tags], :on => :tags).owner(current_user.id).paginate :all, :page => params[:page], :order => ''created_at DESC'' else
2009 Jul 23
11
Problem with named_scope
Here are my scopes: default_scope :order => ''posted_on DESC'', :conditions => { :status => ''visible'' } named_scope :positive, :conditions => { :rating => ''positive'', :status => ''visible'' } named_scope :neutral, :conditions => { :rating => ''neutral'', :status =>
2010 Sep 01
4
deprecation warning in Rails 3 about Base.named_scope
I recently upgraded to Rails 3, and this error has come up ubiquitously: DEPRECATION WARNING: Base.named_scope has been deprecated, please use Base.scope instead. Any ideas on how to get rid of it? Or should I just wait for something? There''s actually no place in my application where the code "Base.named_scope" exists, so I assume the problem is inherent in gems that
2009 Jul 11
2
offeride :limit named_scope default_scope
Hi, Rails 2.3.2 class TestD < ActiveRecord::Base default_scope :limit => 12 named_scope :limit, lambda { |num| { :limit => num} } end ruby script/console >> TestD.all TestD Load (0.7ms) SELECT * FROM "test_ds" LIMIT 12 => [] >> TestD.limit(14) TestD Load (0.3ms) SELECT * FROM "test_ds" LIMIT 12 => [] Any ideas why the default limit
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,
2009 Nov 01
1
please help - complicated polymorphic association
I am trying to build a shared-appointment system, where users can subscribe to appointments and be updated whenever changes are made to them. I have three objects in this system, appointments, users, and subscribers. Subscribers are a polymorphic object like so: class Subscriber < ActiveRecord::Base belongs_to :user belongs_to :subscribable, :polymorphic => true end The tricky part is
2010 Jun 24
3
DRY a named scope
Is there a way to DRY this up a bit? named_scope :has_valid_sysoid, lambda{|sysoid| (sysoid.nil?) ? {:conditions => ["nodesysoid IS NOT NULL AND nodelabel LIKE ''%-to-%''"], :include => [:ipinterface, :alarm]} : {:conditions => ["nodesysoid IS NOT NULL AND nodelabel LIKE ''%-to-%'' AND nodesysoid = ? ", sysoid], :include =>
2010 Feb 11
3
Parameterized ActiveRecord Associations: Any such thing?
Hi list, how are ya? So, my current project is just begging for the ability to have parameterized associations in my ActiveRecord classes. Basically I need something that is a cross between named scopes and standard associations (has_many specifically). I''m wondering if such a thing exists or, if not, if anyone else has an elegant, equivalent solution? Example: class Sprocket <
2008 May 13
6
Testing that named_scope is defined
Hi guys, I''m just beginning to use RSpec and I ran into the issue of testing a named_scope. I''m not actually trying to test its behavior, as it''s not my code, but I wanted to test at least that it''s defined. I tried doing this: describe Post, ".most_recent" do it "should be defined" do Post.method_defined?(:most_recent).should be_true
2009 Oct 17
2
Skip default_scope when running migrations
Hi, I was wondering if there is a way to skip the application of a named_scope to calls made in legacy migrations. I am working with some old migrations that include some data manipulation tasks, and my default scope is preventing those migrations from running. I''m trying to avoid editing those migration files with with_exclusive_scope. Thanks, -G -- Posted via
2006 Apr 01
3
acts_as_taggable, wrong number of arguments
Hello, When I try: @tagged_items = Problem.find_tagged_with :all => ''kuba'' or @tagged_items = Problem.tags_count :limit => 100 I get this error: ArgumentError in Volume#index wrong number of arguments (2 for 3) RAILS_ROOT: script/../config/.. Application Trace | Framework Trace | Full Trace
2012 Feb 22
1
Collect users who posted items with ActsasTaggable on Tag in rails 3
I am using Rails 3 and Acts as taggable on in my application. I am fetching the articles associated with the tag by Article.tagged_with("tagname") and Blog.tagged_with("tagname") Now i would like to collect all the users from the above i.e.., people who are all posted articles and blogs with this tag Please suggest me.. -- Posted via http://www.ruby-forum.com/. -- You
2008 May 22
14
Specifying certain tables NOT to be cleared each example?
Is it possible to specify that certain tables not be cleared on each example. I''ve inherited a project where a good amount of enumerated data is stored in the database (US States, statuses, about 15-20 tables worth. Over all, it''s a reasonable decision that leads to solid production code (acts_as_enumerated is good). This data is read-only and relatively static; any
2009 May 12
4
has_many :through and scopes: how to mutate the set of associated objects?
I have a model layer containing Movie, Person, Role, and RoleType, making it possible to express facts such as "Clint Easterbunny is director of the movie Gran Milano". The relevant model and associations look like this class Movie < ActiveRecord::Base has_many :roles, :include => :role_type, :dependent => :destroy has_many :participants, :through => :roles, :source
2010 Apr 07
3
Recommendation for searching with regards to timestamp & foreign key attributes
hi guys, I need a recommendation for searching with regards to timestamp & foreign key attributes. Sounds a bit too much but here''s an example. Suppose we have a "blog" object. It has many attributes such as - title - content - status_id - created_at - updated_at There are also "status" objects which have the following statuses, "new",
2010 Sep 23
6
Named scope in named scope ??
Hi, I would like to return a combination of named scopes in a named scope : For example, I have a named scope filter and I want to add a named scope eval_filters like Product.eval_filters([''x'',''y'',''z'']) is equivalent to Product.filter(''x'').filter(''y'').filter(''z'') Anybody know how can I
2010 Jun 26
4
Time-dependent values/constants in Models: An issue or not?
Hi there, I remember reading in the comments of a Rails blog something along these lines: "Since a Model is loaded only once in production development (at server start), certain time-dependent ''constants'' that you have placed in a method of a Model will always return the same value for those ''constants'', i.e. the value the ''constant'' had
2009 Jul 31
8
Would like include model association in to_xml
i have: class Library << ActiveRecord::Base has_many :books end class Book << ActiveRecord::Base belongs_to :library end in my controller i have: render :xml=> Library.find(:all).to_xml(:include=>books) but, i would like put a condition in the books ( e.: pages >= 100 ) i would like to create a xml with all Libraries, but books with pages more than 100) How to
2010 Jan 27
2
has_many, through with nested models?
First the data model: class Forum < ActiveRecord::Base has_many :topics, :dependent => :destroy, :order => ''created_at desc'' end class User < ActiveRecord::Base has_many :topics, :dependent => :destroy has_many :comments, :dependent => :destroy has_many :replies, :dependent => :destroy end class Topic < ActiveRecord::Base belongs_to
2008 Apr 04
0
named_scope and ordering
Hi, this is a general design question and I liked to see how other people handle the following situation: Before named_scope I wrote custom finders for my model classes. Something like # order.rb class Order < ActiveRecord::Base class << self def find_all_marked find(:all, :conditions => {:marked => 1}, :order => ''name ASC'') end end end Now