当前位置:网站首页>How do you adjust the scope of activerecord Association in rails 3- How do you scope ActiveRecord associations in Rails 3?
How do you adjust the scope of activerecord Association in rails 3- How do you scope ActiveRecord associations in Rails 3?
2022-07-03 02:51:00 【javail】
problem :
I have a Rails 3 project. I have one Rails 3 project .With Rails 3 came Arel and the ability to reuse one scope to build another. With Rails 3,Arel You can reuse one scope to build another .I am wondering if there is a way to use scopes when defining a relationship (eg a "has_many"). I want to know if there is a way to use scope when defining relationships ( for example “has_many”).
I have records which have permission columns. I have records , There are permission columns .I would like to build a default_scope that takes my permission columns into consideration so that records (even those accessed through a relationship) are filtered. I want to build a default_scope, It takes my permission column into account , In order to filter records ( Even records accessed through relationships ).
Presently, in Rails 3, default_scope (including patches I've found) don't provide a workable means of passing a proc (which I need for late variable binding). at present , stay Rails 3 in ,default_scope( Including the patch I found ) No delivery provided proc It's a feasible way ( I need late variable binding ).Is it possible to define a has_many into which a named scope can be passed? Is it possible to define a that can pass a named range has_many?
The idea of reusing a named scope would look like: The idea of reusing named ranges is as follows :
Orders.scope :my_orders, lambda{where(:user_id => User.current_user.id)}has_many :orders, :scope => Orders.my_ordersOr implicitly coding that named scope in the relationship would look like: Or the content of the named range in the implicit encoding relationship is as follows :
has_many :orders, :scope => lambda{where(:user_id => User.current_user.id)}I'm simply trying to apply default_scope with late binding. I'm just trying to default_scope Apply to late binding .I would prefer to use an Arel approach (if there is one), but would use any workable option. I prefer to use it Arel Method ( If any ), But I will use any feasible option .
Since I am referring to the current user, I cannot rely on conditions that aren't evaluated at the last possible moment, such as: Because I mean the current user , So I can't rely on the conditions that haven't been evaluated at the last moment , for example :
has_many :orders, :conditions => ["user_id = ?", User.current_user.id]Solution :
Reference resources : https://stackoom.com/en/question/A7Yi边栏推荐
- Matlab tips (24) RBF, GRNN, PNN neural network
- C语言中左值和右值的区别
- Use cve-2021-43893 to delete files on the domain controller
- Gbase 8C system table PG_ amproc
- How to change the panet layer in yolov5 to bifpn
- 【翻译】后台项目加入了CNCF孵化器
- The process of connecting MySQL with docker
- Pytest (6) -fixture (Firmware)
- Yiwen takes you to know ZigBee
- Gbase 8C system table PG_ constraint
猜你喜欢

【Flutter】shared_ Preferences local storage (introduction | install the shared_preferences plug-in | use the shared_preferences process)

Baidu map - surrounding search

xiaodi-笔记
![[translation] modern application load balancing with centralized control plane](/img/b0/22e9bf098d580b2af67255ddcdc0d5.jpg)
[translation] modern application load balancing with centralized control plane

MATLAB小技巧(24)RBF,GRNN,PNN-神经网络
![[hcia]no.15 communication between VLANs](/img/59/a467c5920cbccb72040f39f719d701.jpg)
[hcia]no.15 communication between VLANs

C language beginner level - pointer explanation - paoding jieniu chapter

Three.js本地环境搭建

Practice of traffic recording and playback in vivo

【翻译】后台项目加入了CNCF孵化器
随机推荐
SqlServer行转列PIVOT
左连接,内连接
HW initial preparation
Informatics Olympiad one general question bank 1006 a+b questions
[fluent] futurebuilder asynchronous programming (futurebuilder construction method | asyncsnapshot asynchronous calculation)
Gbase 8C system table PG_ am
random shuffle注意
The solution of "the required function is not supported" in win10 remote desktop connection is to modify the Registry [easy to understand]
js根据树结构查找某个节点的下面的所有父节点或者子节点
Summary of interview project technology stack
【富瀚6630编码存录像,用rtsp服务器及时间戳同步实现vlc观看录像】
处理数据集,使用LabelEncoder将所有id转换为从0开始
Strategy application of Dameng database
Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers
[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)
为什么会选择框架?选择什么样的框架
Principle and application of database
tensor中的append应该如何实现
I2C 子系統(四):I2C debug
Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)