Questions tagged [scopes]

An OAuth Scope is a permission setting that limits the permissiveness of a given OAuth Token. Clients therefore provide a list of desired Scopes when obtaining a Token (alongside standard OAuth ClientId and Client Authentication details). The Token will then be granted (or not) according to the Authentication process and the Scopes granted for the given Client Id

383 questions
0
votes
1 answer

Rails, how do I chain scopes with an “OR” operator between them?

This is a question that spun out of "Rails, how do I chain scopes with an "and" operator between them?". In the accepted answer, the code example generates SQL looking something like: "where 'age' similar to '%(foo|bar)%' AND 'name' similar to…
Majoren
  • 983
  • 5
  • 16
  • 36
0
votes
1 answer

Rails, how do I chain scopes with an "and" operator between them?

I have a scope that look like this: scope :attr_similar_to, -> (attr, strings) { where("#{attr} similar to ?", "%(#{strings})%") } The way I use this scope is that iterate through a number of attributes and for each attribute I send the attribute…
Majoren
  • 983
  • 5
  • 16
  • 36
0
votes
1 answer

Rails 4: Parent has_one Child with a specific related ChildType

I have a Parent who has many Children, but only one Firstborn. The Firstborn is a Child with a related ChildType of "firstborn". class Parent has_many :children has_one :firstborn, -> {…
Dan L
  • 4,319
  • 5
  • 41
  • 74
0
votes
2 answers

SQL query for Rails Scope, Disjoint?

I am trying to find the total count of fruits that belong to a supermarket that do not have associated Items records. My relationship is: Supermarkets has_many fruits and Supermarkets has_many items. Items are linked to fruits by their external_upc…
rii
  • 1,578
  • 1
  • 17
  • 22
0
votes
4 answers

precedence of (local) variables over class members

While preparing for sitting the Java exams i just came across this snippet class Person { static class Male { static String Desc = "Male"; } static Gender Male = new Gender(); } class Gender { String Desc = "Gender"; } public…
Andrew Tobey
  • 915
  • 3
  • 10
  • 27
0
votes
1 answer

Python modules - Scopes

I found what I think is peculiar behaviour by python 3.4. I made these small files to illustrate the problem I am facing. To focus on the problem, I now have a python program(module), peculiar.py, containing a class, and some functions. One of the…
Stacker
  • 1
  • 1
0
votes
2 answers

Scope on following association

I am trying to get back into using my scopes again, encountering some issues. I have the following 3 models class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable,…
Richlewis
  • 15,070
  • 37
  • 122
  • 283
0
votes
1 answer

Scope ordering by reverse order not working

I have my scope: scope :latest_photos, -> {order(:created_at).reverse_order.limit(10)} It's supposed to put the latest photos in first place right? Well photos get put on the last place instead. I've also tried: scope :latest_photos, ->…
Gibson
  • 2,055
  • 2
  • 23
  • 48
0
votes
2 answers

AngularJS : How to access scopes created by ng-repeat?

I have the following:

In the record…
user2944669
  • 165
  • 10
0
votes
1 answer

Adding a scope to a has_many through association in Rails

I have a Project and User models joined by a Membership model. I want to retrieve a project's members except one user. project.members.where.not(id: current_user) Like this answer, I want to use a scope: class User < ActiveRecord::Base scope…
Jumbalaya Wanton
  • 1,601
  • 1
  • 25
  • 47
0
votes
2 answers

Query based on number of associated models

I'm working on a project where I need to scope a model by the number of associated models under a where clause. This is the best I could come up with: Subscription.where('message_cap > ?', TextMessage.where('created_at > ?',…
Dylan Karr
  • 3,304
  • 4
  • 19
  • 29
0
votes
3 answers

Call to undefined function with PHP

I have this class: class testclass{ function func1(){ return "hello"; } function func2(){ echo func1(); } } When I am running $test = new testclass(); $test->func2(); I get an error: Fatal error: Call to undefined…
Friedrich
  • 2,211
  • 20
  • 42
0
votes
1 answer

rails 4 scopes with NOT equal and associations

I have a instance variable in my controller that I'm trying to convert into a scope for my model. Instance variable: products @products_with_user_differences = Product.where{|p| p.last_user != p.user.username && p.asset_type.name == "Computer"…
Devin
  • 1,011
  • 2
  • 14
  • 30
0
votes
1 answer

Hard time creating a class scope for HABTM relation

This is my simplified situation: class Producer has_and_belongs_to_many :rules end class Rule has_and_belongs_to_many :producers end But Rule happens to follow a STI structure. So I have this: class Producer has_and_belongs_to_many :rules …
0
votes
1 answer

Yii: Use a different scope based on user role

I have two levels of admins who can create and update users, "Admin" and "Manager". In my User _form.php I have a "user_type" dropdown that has my account levels. I want to limit managers from creating "Admin" accounts, and obviously hide the…
McB
  • 1,082
  • 1
  • 18
  • 36