当前位置:网站首页>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边栏推荐
- Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes
- C语言初阶-指针详解-庖丁解牛篇
- Source code analysis | layout file loading process
- [fluent] listview list (map method description of list set | vertical list | horizontal list | code example)
- Cancer biopsy instruments and kits - market status and future development trends
- Yiwen takes you to know ZigBee
- Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
- Process the dataset and use labelencoder to convert all IDs to start from 0
- [translation] flux is safe. Gain more confidence through fuzzy processing
- [hcia]no.15 communication between VLANs
猜你喜欢

内存泄漏工具VLD安装及使用

左连接,内连接

Practice of traffic recording and playback in vivo

Random Shuffle attention

Add MDF database file to SQL Server database, and the error is reported

TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制

Joking about Domain Driven Design (III) -- Dilemma

Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception

Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes
![ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc](/img/cb/145937a27ef08050a370d5a255215a.jpg)
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
随机推荐
Sous - système I2C (IV): débogage I2C
Check log4j problems using stain analysis
Matlab tips (24) RBF, GRNN, PNN neural network
Principle and application of database
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
Informatics Olympiad one general question bank 1006 a+b questions
Counter统计数量后,如何返回有序的key
[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)
Two dimensional format array format index subscript continuity problem leads to return JSON format problem
Three.js本地环境搭建
Linear rectification function relu and its variants in deep learning activation function
Kubernetes family container housekeeper pod online Q & A?
The Linux server needs to install the agent software EPS (agent) database
Random Shuffle attention
Hcip137-147 title + analysis
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
Strategy application of Dameng database
Gbase 8C system table PG_ amop
The core idea of performance optimization, dry goods sharing
HTB-Devel