当前位置:网站首页>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_orders
Or 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边栏推荐
- 疫情当头,作为Leader如何进行代码版本和需求开发管控?| 社区征文
- I2C subsystem (IV): I2C debug
- 你真的懂继电器吗?
- 迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常
- 2022-2028 global splicing display industry research and trend analysis report
- 当lambda没有输入时,是何含义?
- 基于can总线的A2L文件解析(2)
- Why choose a frame? What frame to choose
- How to implement append in tensor
- Kubernetes family container housekeeper pod online Q & A?
猜你喜欢
C language beginner level - pointer explanation - paoding jieniu chapter
Matlab tips (24) RBF, GRNN, PNN neural network
[hcia]no.15 communication between VLANs
【翻译】后台项目加入了CNCF孵化器
用docker 連接mysql的過程
The Linux server needs to install the agent software EPS (agent) database
vfork执行时出现Segmentation fault
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
where 1=1 是什么意思
Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes
随机推荐
Gbase 8C trigger (III)
random shuffle注意
超好用的日志库 logzero
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
从C到Capable-----利用指针作为函数参数求字符串是否为回文字符
Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
Your family must be very poor if you fight like this!
[C语言]给账号密码进行MD5加密
tensorflow转pytorch笔记;tf.gather_nd(x,y)转pytorch
Today, it's time to copy the bottom!
sql server 查询指定表的表结构
Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers
[translation] flux is safe. Gain more confidence through fuzzy processing
一文带你了解 ZigBee
Unity3d human skin real time rendering real simulated human skin real time rendering "suggestions collection"
Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
【翻译】具有集中控制平面的现代应用负载平衡
I2C 子系统(一):I2C spec
Matlab tips (24) RBF, GRNN, PNN neural network
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)