当前位置:网站首页>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边栏推荐
- Add automatic model generation function to hade
- 定了,就选它
- What does it mean when lambda is not entered?
- Gbase 8C system table PG_ auth_ members
- Deep Reinforcement Learning for Intelligent Transportation Systems: A Survey 论文阅读笔记
- I2C subsystem (III): I2C driver
- I2C 子系统(二):I3C spec
- Check log4j problems using stain analysis
- [C language] MD5 encryption for account password
- sql server 查詢指定錶的錶結構
猜你喜欢

HW-初始准备
![[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)](/img/6e/67bc187a89fb9125856c78c89f7bfb.gif)
[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)

I2C 子系统(一):I2C spec

Check log4j problems using stain analysis
![[principles of multithreading and high concurrency: 1_cpu multi-level cache model]](/img/c7/6b5ab4ff7379bfccff7cdbb358ff8f.jpg)
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]

搭建私有云盘 cloudreve

【翻译】后台项目加入了CNCF孵化器

Basic operation of binary tree (C language version)

Deep Reinforcement Learning for Intelligent Transportation Systems: A Survey 论文阅读笔记

基于can总线的A2L文件解析(2)
随机推荐
【翻译】Flux安全。通过模糊处理获得更多信心
[fluent] future asynchronous programming (introduction | then method | exception capture | async, await keywords | whencomplete method | timeout method)
疫情当头,作为Leader如何进行代码版本和需求开发管控?| 社区征文
SQL statement
基于can总线的A2L文件解析(2)
Gbase 8C system table PG_ attribute
Practice of traffic recording and playback in vivo
Wechat - developed by wechat official account Net core access
用docker 连接mysql的过程
I2C 子系統(四):I2C debug
[C language] MD5 encryption for account password
[fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)
HW-初始准备
Sous - système I2C (IV): débogage I2C
[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)
I2C 子系统(二):I3C spec
random shuffle注意
Informatics Olympiad one general question bank 1006 a+b questions
xiaodi-笔记
Joking about Domain Driven Design (III) -- Dilemma