search for: default_scope

Displaying 18 results from an estimated 18 matches for "default_scope".

2013 Jun 15
1
A puzzle about default_scope
Hi, guys I have a puzzle about default_scope. Suppose I have two model: class User < ActiveRecord::Base has_many :blogs default_scope where(deleted_at: nil) end class Blog < ActiveRecord::Base belongs_to :user end I want to produce sqlselect blogs.* from blogs inner join users on users.id = blogs.user_id and users.deleted_at...
2011 Feb 02
6
how to set default_scope for the whole application?
I know I can set default_scope for individual active record model, but can I set one up for the whole application? thanks -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@pu...
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 => [] An...
2012 Jul 25
0
Rails3-default_scope throws exception: undefined method abstract_class? for Object:Class
...ase<http://stackoverflow.com/questions/2328984/rails-extending-activerecordbase>, I decided to use monkey patch to do above. Created monkey patch file in config/initializer/active_record_patch.rb: class ActiveRecord::Base def inactive update_attribute(:available, false) end default_scope :available => true end Getting following error when add the default_scope */gems/ruby-1.9.2-p290/gems/activerecord-3.0.9/lib/active_record/base.rb:1212:in class_of_active_record_descendant'': undefined methodabstract_class?'' for Object:Class (NoMethodError)* -- You receiv...
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
2013 Apr 08
1
cattr_accessor and Thread.current prblems
...o convert three applications to multitenant, all of them have same structure difference is only in little functions and template designs. All of them using cattr_accessor for setting currencies and other data, and it works perfectly Now i added app_id as cattr_accessor to App model to use it in default_scope to implement multi-tenancy class App < ActiveRecord::Base attr_accessible :active, :name cattr_accessor :app_id, :app_name end on development mode no problem, but in production values are not accessible in models. also tried to use Thread.current, same result, on production does not work....
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 =...
2011 Sep 15
1
bypass defualt scope.
class Shop < ActiveRecord::Base has_many :documents, :dependent => :restrict end class Document < ActiveRecord::Base belongs_to :shop default_scope :order => ''updated_at DESC'' end in the Shop show view I have: - for document in @shop.documents %li(id="shop_documents")= link_to document.subject, shop_document_url(@shop, document) I want list document based on reference_date attribute and not using default s...
2009 Dec 28
2
Override .find, .find_by_id, etc...
I read these: http://www.ruby-forum.com/topic/185297#new http://www.freezzo.com/2008/05/14/override-default-find-conditions-for-model/ it works, it override the .find perfectly, however it does not cover .find_by_id or other .find_by_XXX Is there anyway to override all the find function of a modal? I want to set the default "select" for User modal, only return name and id, but not the
2011 Jul 11
2
Can't get this Rspec test to pass
...[0].extract_options! if args send :include, InstanceMethods set_global_scope(scope,options[:with_global_scope]) if options[:with_global_scope] send :before_filter, "set_scope_for_#{scope}".to_sym if self.ancestors.include? ActionController::Base send :default_scope, where(scope.to_sym => send("current_scope_for_#{scope}".to_sym)[:finder_scope]).create_with(scope.to_sym => send("current_scope_for_#{scope}".to_sym)[:creator_scope]) if (self.ancestors.include? ActiveRecord::Base) && Thread.current[scope.to_sym] en...
2010 Jul 04
1
Rails 3: ActiveRecord .include not working
Really no idea what''s up... class Auction < ActiveRecord::Base has_and_belongs_to_many :categories end class Category < ActiveRecord::Base has_and_belongs_to_many :auctions default_scope order(''title'') scope :active, where(:active => true) end class CategoriesController < ApplicationController respond_to :html, :json # GET /categories/:id def show @category = Category.where(:id => params[:id]).include(:auctions).first respond_with(@categ...
2011 Aug 01
0
ActiveRecord:: DangerousAttributeError only in console
...and I''m having a very strange behavior during implementation: 1) initializing / creating the object (which maps to the table) on the console I get the message "ActiveRecord:: DangerousAttributeError: reference? is defined by ActiveRecord ". I''ve tried a few approaches (default_scope, override the instance_method_already_implemented?) But all without success 2) running the code through the browser, i don''t get this error, I can persist the object on the database. When i try and fetch it afterwards, i get an error when accessing "self.reference". The strange...
2012 Apr 17
0
Request for adding an "alias"/"as" to ActiveRecord
...tion_type'' table that actually should be something like ''fields''. Also it can have a parent field and deletion is handled by setting a ''deleted'' column, so here is the basic class: class Field self.table_name = ''condition_type'' default_scope where(deleted: false) belongs_to :parent, class: ''Field'' end Okay, first set up is awesome! Now the issue: I''m implementing the tree view in a lazy way using AJAX, so I only need to check for the existence of children. The easy way is to iterate over the fields lik...
2012 Jul 05
2
Addition to has_many - a ':source_scope' option
Was looking to work on a small addition (to has_many) which will be useful to me and others alike. A few technical details about the addition: Basically wanting to have something like, has_many :subscribers, through: :subscriptions, *source_scope:* :deleted We currently have to do this in our code as, has_many :subscribers, through: :subscriptions, conditions:
2010 Dec 23
6
Difference between rake test:units and individually running ruby -I test test/unit/something_test.rb ?
Here''s my issue: running ruby -I test test/unit/something_test.rb for each of my unit tests works perfectly. However, running rake test:units brings errors in all of them - some object becomes nil for some reason. Why might this be happening? Specifics: the object that is successfully not nil when I run the unit tests one-by-one but becomes nil when I do rake test:units is defined like
2010 Aug 29
4
Wrong class being returned in association
I''m using Rails 3.0.0rc and have the following models: class User  has_many :readings  has_many :conversations, :through=>:readings end class Reading  belongs_to :user  belongs_to :conversation end class Conversation  has_many :readings  has_many :users, :through=>:readings end and this controller code: class ConversationsController  def show    @user =
2010 Dec 30
3
rake db:seed with has_many through (m:n with seperate table)
...t; ActiveRecord::Base # attr_accessible :name, :category has_many :tasks, :dependent => :destroy has_many :sharedtabs, :dependent => :destroy has_many :users, :through => :sharedtabs end class Task < ActiveRecord::Base # attr_accessible :name belongs_to :tab default_scope :order => ''tasks.created_at DESC'' end -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe fr...
2011 Feb 24
7
Fast in MySQL console, slow in ActiveRecord
Has anyone experienced an ActiveRecord query being much much slower than running the equivalent query in the MySql console? I am running a simple "group by" query with one condition on a table with 7 million records. When I run EXPLAIN it says that it will have to scan over all the records - well that''s OK. In the MySQL query it takes 1min 40secs which is OK for me - this