Git Product home page Git Product logo

Comments (2)

ernie avatar ernie commented on September 17, 2024

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:

  1. Assign the variable locally before the DSL block, and access it as you would normally.
  2. 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.
  3. Wrap the method or instance variable inside the block with my{}. Person.where{name == my{some_method_to_return_a_name}}

from squeel.

JeanMertz avatar JeanMertz commented on September 17, 2024

Sorry I should've read that. My bad. Thank you for pointing that out.

from squeel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.