Comments (2)
Yep -- see the section on "The Squeel Query DSL" from the docs. Specifically:
An important gotcha, before we begin: The Squeel DSL works its magic using instance_eval. If you've been working with Ruby for a while, you'll know immediately that this means that inside a Squeel DSL block, self isn't the same thing that it is outside the block.
This carries with it an important implication: Instance variables and instance methods inside the block won't refer to your object's variables/methods.
Don't worry, Squeel's got you covered. Use one of the following methods to get access to your object's methods and variables:
- Assign the variable locally before the DSL block, and access it as you would normally.
- Supply an arity to the DSL block, as in Person.where{|dsl| dsl.name == @my_name} Downside: You'll need to prefix stubs, keypaths, and functions (explained below) with the DSL object.
- Wrap the method or instance variable inside the block with my{}. Person.where{name == my{some_method_to_return_a_name}}
from squeel.
Sorry I should've read that. My bad. Thank you for pointing that out.
from squeel.
Related Issues (20)
- Using squeel with existing scopes ? HOT 1
- Literals don't work well with nil HOT 4
- Using BETWEEN condition in squeel?
- Undefined method | (pipe) HOT 2
- Accessing a records associations with a scope HOT 2
- Support for rewhere
- Group_by not working HOT 1
- Using complex IN + OR scope inside an association results in invalid SQL on join condition HOT 5
- rails 5 support HOT 18
- Support for PostgreSQL arrays
- Subquery generation when using a Relation as a parameter in regular where() HOT 4
- Performance issues HOT 1
- Default scope where conditions with or in rails 4 and squeel HOT 4
- MySQL concat function HOT 1
- makes #reorder break #last
- common table expressions (CTEs)
- Active record 5 support HOT 1
- is gem still maintained? HOT 16
- Convert column HOT 1
- Undefined method `alias_method_chain' HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from squeel.