Questions tagged [named-scope]

339 questions
0
votes
2 answers

Why NamedScopes invoke dispose methods from finalizer?

I noticed that when I use IDisposable objects inside Ninject named scope my Dispose method is called from finalizer. But my object or some of it references may be already finalized at that point. Am I missing something? Is it a correct behavior or a…
Vlad
  • 3,001
  • 1
  • 22
  • 52
0
votes
1 answer

named_scope conditions and timezone mismatch

Here is the setup: end_date = DateTime.parse('2010-01-01 12:00:00-04') and sometimes it's initialized: end_date = 1.days.ago The question... do these named_scope(s) generate the same EXACT SQL? named_scope :before, lambda { |end_date| {…
Richard
  • 10,122
  • 10
  • 42
  • 61
0
votes
1 answer

rails 4 cross model named scopes

What I want to do is create appropriate named scopes to get all reports of a logged in user that were created 3 days ago class User < ActiveRecord::Base has_many :appraisals end class Appraisal < ActiveRecord::Base belongs_to :user …
v8soup
  • 19
  • 8
0
votes
0 answers

Is it possible to define a global scope on Activerecord::Base?

I know I can make a module that defines a scope and include this module in a model, following, for example, this question's discussion. But say I have 100 models, all of which have created_at fields. I want to have a scope reading from created_at,…
Epigene
  • 3,634
  • 1
  • 26
  • 31
0
votes
1 answer

Help refactoring named_scope

I have the following named_scope: named_scope :commentors, lambda { |*args| { :select => 'users.*, count(*) as total_comments', :joins => :comments, :conditions => { :comments => { :public_comment => 1, :aasm_state =>…
keruilin
  • 16,782
  • 34
  • 108
  • 175
0
votes
1 answer

Why are these named_scopes causing a duplicate INNER JOIN?

I have a Model which I am using to track permissions in a hierarchical organization using the awesome_nested_set plugin. I'm running into a problem where two named_scopes, when chained together, are creating a duplication INNER JOIN. class Group <…
Adam Lassek
  • 35,156
  • 14
  • 91
  • 107
0
votes
1 answer

Choose scope based on string/symbol without send

how to call a active record named scope with a string and Access named scope dynamically have information on how to choose a scope based on a string or symbol, if you're willing to use send or public_send. I'm rather concerned by the security…
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
0
votes
3 answers

Scope with joins in Rails 4.2

I've got code similar to class Article < ActiveRecord::Base has_many :comments scope :with_comments, joins(:comments) end based on this answer, but when I use it in Rails 4.2, I get…
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
0
votes
3 answers

named_scope -- Finding entries where the field is neither null nor empty/blank

I only want to find the records that aren't null or empty/blank, currently I have; named_scope :in_gallery, :conditions => ["gallery IS NOT NULL"] (gallery is a string) but if the user inputs then deletes a title then this empty string is included…
raphael_turtle
  • 7,154
  • 10
  • 55
  • 89
0
votes
2 answers

How do I use a named_scope to filter records in my model

I have a model "Product" with a "description" field. Now I want to have a link in the index page that when clicked will show all products where the description is blank (empty). In the model I have defined a named_scope like this named_scope…
kibyegon
  • 3
  • 1
0
votes
1 answer

Getting WELD-001303 error when implementing custom CDI extension for @SessionScoped scope

I'm trying to implement a custom CDI scope and I thought it's the easiest to start by extending the existing @SessionScoped. I started by following this tutorial. However, when visiting an XHTML page which references a CDI bean with my scope, this…
SputNick
  • 1,231
  • 5
  • 15
  • 26
0
votes
1 answer

MySQL to PostreSQL and Named Scope

I've got a named scope for one of my models that works fine. The code is: named_scope :inbox_threads, lambda { |user| { :include => [:deletion_flags, :recipiences], :conditions => ["recipiences.user_id = ? AND deletion_flags.user_id IS NULL",…
Lowgain
  • 3,254
  • 5
  • 27
  • 30
0
votes
1 answer

rails named_scope issue with eager loading

Two models (Rails 2.3.8): User; username & disabled properties; User has_one :profile Profile; full_name & hidden properties I am trying to create a named_scope that eliminate the disabled=1 and hidden=1 User-Profiles. Moreover, while the User…
craig
  • 25,664
  • 27
  • 119
  • 205
0
votes
2 answers

named scoped NOT IN, how to?

how can I write a NOT IN in named scope syntax? For example, User :has_many Photos, how can I define: User.has_no_photo and returns all users who are not in the Photo model? thanks!
ohho
  • 50,879
  • 75
  • 256
  • 383
0
votes
1 answer

Wrong number of Arguments (0 for 1) Error using Rails Scope to find all in current month

I am new to scopes and when creating this found what I thought would work here Rails scope created within month. However, my code below, gives wrong number of arguments (0 for 1) and I am unsure why. I appreciate any help offered on the matter. The…
joemac
  • 23
  • 2