default-scope Questions
6
Suppose I have a Post model, and a Comment model. Using a common pattern, Post has_many Comments.
If Comment has a default_scope set:
default_scope where("deleted_at IS NULL")
How do I easily r...
Conjuration asked 18/10, 2010 at 20:30
5
Everywhere on the internet people mention that using the rails default_scope is a bad idea, and the top hits for default_scope on stackoverflow are about how to overwrite it. This feels messed up, ...
Conklin asked 1/8, 2014 at 19:26
2
Solved
So basically I have two classes, Book and Author. Books can have multiple authors and authors can have multiple books. Books have the following default scope.
default_scope :order => "publish_a...
Vientiane asked 16/3, 2012 at 23:45
5
In a resource registered with ActiveAdmin, I have the following default_scope defined for the model:
default_scope :order => 'activities.updated_at DESC'
This apparently prevents me from bein...
Fondafondant asked 27/2, 2012 at 20:41
2
Solved
My app has not only Users but also Admins and SuperAdmins. Since all three share the same attributes i'd like to use only one Table with an additional attribute "role" that can either be "user", "a...
Toreador asked 7/9, 2012 at 13:38
8
Solved
In my Rails app have a default scope that looks like this:
default_scope order: 'external_updated_at DESC'
I have now upgraded to Rails 4 and, of course, I get the following deprecation warning ...
Premaxilla asked 29/8, 2013 at 8:39
2
Solved
class CreateCrews < ActiveRecord::Migration
def self.up
create_table :crews do |t|
t.string :title
t.text :description
t.boolean :adult
t.boolean :private
t.integer :gender_id
t.boolean ...
Fujio asked 20/10, 2010 at 6:10
2
Solved
I'm using the paranoia gem to "soft-delete" records. Now I need to eager load these records, some of which might have been deleted, for an associated model. Paranoia adds this default_scope to the ...
Headwaters asked 11/11, 2012 at 21:38
3
Solved
my model has default_scope(:order => 'created_at' )
my tests (rspec, factory girl, shoulda, etc.)
are:
require 'spec/spec_helper.rb'
describe CatMembership do
context "is valid" do
subject { Fa...
Cedar asked 28/7, 2011 at 3:18
2
Solved
On Rails 3.1 RC6, given
class Animal < ActiveRecord::Base
default_scope where(legs: 4)
end
The following does not work as expected:
class Man < Animal
default_scope unscoped.where(legs:...
Starrstarred asked 30/8, 2011 at 5:53
3
Solved
I know named_scope has been changed to scope in rails 3.
How do I perform default_scope in rails 3, I've had a good google but found nothing for defaults scopes.
Chen asked 2/4, 2010 at 21:34
2
Solved
I can't find too much documentation on applying a default scope to a model in yii, I was wondering if someone could explain or point me in the right direction.
The quick version of my question:
I...
Antithesis asked 15/8, 2012 at 13:3
4
I believe this is a bug in Rails 3. I am hoping someone here can steer me in the correct direction. The code posted below, is purely for illustration of this problem. Hopefully this does not confus...
Obidiah asked 15/10, 2010 at 16:7
2
Solved
I have a situation where the behavior of an existing app is changing and it's causing me a major headache.
My app has Photos. Photos have a status: "batch", "queue", or "complete". All the existin...
Astigmatism asked 2/8, 2011 at 22:9
3
Solved
I need to do some filtering on my ActiveRecord models, I want to filter all my model objects by owner_id. The thing I need is basically the default_scope for ActiveRecord.
But I need to filter by ...
Interrupter asked 21/5, 2012 at 7:9
1
Solved
In ActiveRecord there is a default_scope class method to specify a default scope. For example
class User < ActiveRecord::Base
default_scope where(:deleted => false)
end
User.all # => SE...
Dendrology asked 26/7, 2012 at 13:0
2
Solved
I've seen a lot of posts regarding this, but none seem to solve my problem. I have a default_scope on a model like so:
default_scope where(:is_active => true).order('LOWER(table.name)');
I ha...
Score asked 4/1, 2012 at 21:59
2
Solved
I've got a model setup like the following:
class User
has_many :items
has_many :words, :through => :items
end
class Item
belongs_to :user
belongs_to :word
default_scope where(:active =&g...
Presidency asked 28/3, 2011 at 18:28
4
Solved
In my Post.rb model, I have default_scope :conditions => {:deleted => 'false'}
But if I try to run Post.find(:all, :conditions => "deleted='false'"), it won't return anything. It's as if ...
Sabu asked 15/1, 2010 at 17:10
2
Solved
I'm trying to set default scope according to some criteria determined by ana ActionController before_filter. In controller:
before_filter :authorize
...
def authorize
if some_condition
@defau...
Konstanz asked 17/4, 2010 at 9:35
1
© 2022 - 2024 — McMap. All rights reserved.