GithubHelp home page GithubHelp logo

active_record_or's People

Contributors

clemensp avatar woahdae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

active_record_or's Issues

incorrect SQL when filtering for multiple columns

User.where(hair_color: 'brunette', figure: 'slim').or.where(hair_color: 'blonde', figure: 'normal')
SELECT users.* FROM users WHERE ((users.hair_color = 'brunette' AND users.figure = 'slim' OR users.hair_color = 'blonde' AND users.figure = 'normal'))

Need to wrap both sides of the OR in parenthesis. This is the SQL what I expect:

SELECT users.* FROM users WHERE ((users.hair_color = 'brunette' AND users.figure = 'slim') OR (users.hair_color = 'blonde' AND users.figure = 'normal'))

Unscoped starting context leads to unexpected SQL

I understand that the intentional behaviour for scopeless initial conditions is: "if you call or on a condition-less scope, it will be ignored", but I would say that is unexpected.

Imagine a scope that is sometimes pre-filtered (by CanCan in our case) for customers, but unfiltered for internal users. We want to show customers their products, and also offers. Here is our one line controller action. CanCan has provided products.

products = products.or.offers

This works for customers, but internal users can only see offers, as the initial scope is unfiltered and therefore dropped. I'd say this was unexpected...?

Creates unnecessary parens

Although they shouldn't damage the logic, the extra parens sure are ugly.

If people find this project useful, it might be worth looking in to this.

Example from the tests:

to_blacklist.where_sql.must_equal(
  "WHERE (((((artist_mentions_count > 0)"\
  " OR (competition_rank > 7)))"\
  " OR (subjective_dislike_rating > 3)))")

Bad SQL when using active_record_or with squeel

I know not whether this is a bug in squeel or active_record_or.

--- animal.rb ---
class Animal < ActiveRecord::Base
attr_accessible :name
scope :a, where { name.matches('%a%') & name.not_in(['ab']) }
scope :b, where("name LIKE '%b%'")
end
--- animal.rb ---

irb(main):082:0> Animal.a.or.b

Expected SQL:
SELECT "animals".* FROM "animals" WHERE ("animals.name LIKE '%a' AND "animals"."name" NOT IN ('abcd')) OR (name LIKE '%b%');

Actual SQL:
SELECT "animals".* FROM "animals" WHERE (("animals"."name" NOT IN ('ab') OR (name LIKE '%b%')))

The first sub-condition in scope :a was dropped (name LIKE '%a').

Not operator (from the TODO list)

Hey @woahdae, I wanted to see if you are still maintaining the project, and plan to add the not functionality along with or.

For anyone else, who stumbles upon this who might have used a where Not A or Not B solution - I'd love to understand how you approached it!

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.