scopes

Getting a GET request param into an @ViewScoped bean

烂漫一生 提交于 2019-11-30 23:29:09
I have a (request-scoped) list from which the user may select a "PQ" (list of links). When clicked or otherwise entered into the browser the main page for each PQ shall be displayed. Each PQ's page is of the form http://localhost:8080/projectname/main.jsf?id=2 Here's the PQ bean first: @Named @ViewScoped public class PqHome implements Serializable { @PersistenceContext(unitName="...") private EntityManager em; private Integer id; private PQ instance; @PostConstruct public void init() { System.out.println("ID is " + id); // ID from URL param instance = em.find(PQ.class, id); } public Integer

rails scope to check if association does NOT exist

和自甴很熟 提交于 2019-11-27 20:30:29
I am looking toward writing a scope that returns all records that do not have a particular association. foo.rb class Foo < ActiveRecord::Base has_many :bars end bar.rb class Bar < ActiveRecord::Base belongs_to :foo end I want a scope that can find all of the Foo's that dont have any bars . It's easy to find the ones that have an association using joins , but I haven't found a way to do the opposite. Rails 4 makes this too easy :) Foo.where.not(id: Bar.select(:foo_id).uniq) this outputs the same query as jdoe's answer SELECT "foos".* FROM "foos" WHERE "foos"."id" NOT IN ( SELECT DISTINCT "bars"

ActiveRecord Rails 3 scope vs class method

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 11:18:31
I'm new to the new query interface of ActiveRecord so I'm still figuring things out. I was hoping someone could explain the difference between using a scope in an ActiveRecord model and just using a class method (ie self.some_method ) From what I can gather, a scope is always expected to return a relation, whereas a class method doesn't necessarily have to. Is this true? For instance, I thought it would make sense to do something like: class Person scope :grouped_counts, group(:name).count end But this doesn't work. I get this error: ArgumentError: Unknown key(s): communicating, failed,

Laravel Passport Scopes

不问归期 提交于 2019-11-27 03:12:26
I am a bit confused on the laravel scopes part. I have a user model and table. How can I assign a user the role of user, customer and/or admin. I have a SPA with vue and laravel api backend. I use https://laravel.com/docs/5.3/passport#consuming-your-api-with-javascript Passport::tokensCan([ 'user' => 'User', 'customer' => 'Customer', 'admin' => 'Admin', ]); How can i assign which user model has which scope(s)? Or are scopes not the same as roles? How would you implement this? Thanks in advance! Or are scopes not the same as roles? The biggest difference between the two is the context they

rails scope to check if association does NOT exist

隐身守侯 提交于 2019-11-26 20:09:44
问题 I am looking toward writing a scope that returns all records that do not have a particular association. foo.rb class Foo < ActiveRecord::Base has_many :bars end bar.rb class Bar < ActiveRecord::Base belongs_to :foo end I want a scope that can find all of the Foo's that dont have any bars . It's easy to find the ones that have an association using joins , but I haven't found a way to do the opposite. 回答1: Rails 4 makes this too easy :) Foo.where.not(id: Bar.select(:foo_id).uniq) this outputs

Laravel Passport Scopes

↘锁芯ラ 提交于 2019-11-26 12:54:26
问题 I am a bit confused on the laravel scopes part. I have a user model and table. How can I assign a user the role of user, customer and/or admin. I have a SPA with vue and laravel api backend. I use https://laravel.com/docs/5.3/passport#consuming-your-api-with-javascript Passport::tokensCan([ \'user\' => \'User\', \'customer\' => \'Customer\', \'admin\' => \'Admin\', ]); How can i assign which user model has which scope(s)? Or are scopes not the same as roles? How would you implement this?