named-scope Questions
9
Solved
I have the following scope for my class called Collection:
scope :with_missing_coins, joins(:coins).where("coins.is_missing = ?", true)
I can run Collection.with_missing_coins.count and get a re...
Fortnight asked 14/8, 2011 at 0:30
5
Solved
I have a scope that acts as a filter. For instance:
class User
scope :in_good_standing, -> { where(:some_val => 'foo', :some_other_val => 'bar' }
end
Because in_good_standing depends o...
Consentient asked 25/4, 2014 at 18:28
1
I have User model which has_many :notifications. Notification has a boolean column seen and a scope called :unseen which returns all notifications where seen is false.
class User < ApplicationR...
Donatello asked 4/5, 2016 at 13:52
7
Solved
I'm using the Rails gem rails3-jquery-autocomplete to add categories to posts.
I would like to restrict the search to include only categories that belong to the current user or post's author in t...
Humiliate asked 30/8, 2011 at 14:5
1
Solved
I wrote a convenience API to define my models in TensorFlow that exposes a scope object. Now I want to verify that the user actually enters the scope before adding operations. How to get the name o...
Gahl asked 17/7, 2016 at 14:41
4
Solved
I've recently started an internship. My employer uses ruby on rails, and I frequently encounter new syntax that I need to look up to understand. I've googled around for a good explanation of named_...
Chapatti asked 2/2, 2011 at 1:42
2
I am trying to combine two scopes or add some more to an existing scope.
scope :public_bids, -> {
where(status: [Status::ACCEPTED, Status::OUTBID, Status::SOLD, Status::NO_SALE],
bid_type: [B...
Soloma asked 25/5, 2016 at 18:41
3
Solved
Say there are 3 models: A, B, and C. Each of these models has the x attribute.
Is that possible to define a named scope in a module and include this module in A, B, and C ?
I tried to do so and g...
Carolinian asked 15/1, 2011 at 11:34
3
Solved
I have a User model. I can check whether a User is an admin by doing a_user.try(:admin?).
I'd like to define a named scope that gets all Users updated within the last X minutes who are not admins....
Naga asked 31/1, 2013 at 10:33
1
Solved
Yes, I know this has been asked before, and yes, I know it is "by design".
But I'd like to do something like this:
@Component(modules = {RealmModule.class})
public interface RealmComponent {
Rea...
Monzonite asked 10/7, 2015 at 13:58
5
Solved
The problem essence as I see it
One day, if I'm not mistaken, I have seen an example of reusing a named_scope to define another named_scope. Something like this (can't remember the exact syntax, b...
Maddocks asked 14/3, 2010 at 20:31
6
Solved
I have
class Foo < ActiveRecord::Base
named_scope :a, lambda { |a| :conditions => { :a => a } }
named_scope :b, lambda { |b| :conditions => { :b => b } }
end
I'd like
class Foo...
Skirret asked 26/8, 2008 at 20:13
3
Is there any way to nest named scopes inside of each other from different models?
Example:
class Company
has_many :employees
named_scope :with_employees, :include => :employees
end
class Emp...
Cristincristina asked 5/3, 2010 at 19:58
7
Solved
Following Problem:
I need something like an empty scope. Which means that this scope is emtpy, but responds to all methods a scope usually responds to.
I'm currently using a little dirty hack. I si...
Hemianopsia asked 17/9, 2010 at 13:45
1
Solved
How should Rails named scopes be tested? Do you test the results returned from a scope, or that your query is configured correctly?
If I have a User class with an .admins method like:
class User ...
Harpsichord asked 7/4, 2014 at 2:29
1
Solved
Abstract
When the design requires an "Abstract Factory Pattern" like stated by the [GoF] including several products and over some product families, then setting up an IoC can become a bit tricky. ...
Natoshanatron asked 6/1, 2014 at 16:27
2
Solved
Assume I have a named scope:
class Foo < ActiveRecord::Base
named_scope :bar, :conditions => 'some_field = 1'
end
This works great for queries and I have a bunch of useful named_scopes de...
Thier asked 10/8, 2009 at 16:17
4
Firstly, I am new to rails so sorry if there is anything that I don't understand correctly. I am wondering how can I populate a model with data fetch thru an API.
Context: I am using a OAuth2 auth...
Paramaribo asked 13/12, 2013 at 15:46
2
Solved
I have a model for user.rb, in which I define a scope for admins, which is users that have the role of admin through a permissions table.
has_many :permissions
has_many :roles, :through => :per...
Kedge asked 18/1, 2013 at 19:56
2
Solved
I am getting this error while accessing scopes.
Here is AR model
class StatisticVariable < ActiveRecord::Base
attr_accessible :code, :name
has_many :statistic_values
scope :logins, where(...
Lal asked 11/9, 2012 at 7:51
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
6
Solved
I have a Rails 3 project. With Rails 3 came Arel and the ability to reuse one scope to build another. I am wondering if there is a way to use scopes when defining a relationship (e.g. a "has_many")...
Apospory asked 9/3, 2010 at 20:33
1
Solved
Is there an equivalent of AR's named scopes? Named scopes are basically filters, that can be wrapped in a method, and then chained.
Here's an example from http://archives.ryandaigle.com/articles/2...
Aeneas asked 30/1, 2013 at 8:53
2
I have named_scope which is reused in multiple ActiveRecord models.
For example:
named_scope :limit, lambda {|limit| {:limit => limit}}
What is the best practice to extract this code to be ...
Selfless asked 9/10, 2008 at 11:19
2
Solved
In my Rails3 model I have these two named scopes:
scope :within_limit, where("wait_days_preliminary <= ? ", ::WAIT_TIME_LIMIT.to_i )
scope :above_limit, where("wait_days_preliminary > ? ", :...
Fendley asked 5/3, 2012 at 22:22
1 Next >
© 2022 - 2024 — McMap. All rights reserved.