Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

where_or for Query and QueryProxy #947

Open
cheerfulstoic opened this issue Aug 30, 2015 · 9 comments
Open

where_or for Query and QueryProxy #947

cheerfulstoic opened this issue Aug 30, 2015 · 9 comments

Comments

@cheerfulstoic
Copy link
Contributor

No description provided.

@subvertallchris
Copy link
Contributor

👍

@cheerfulstoic
Copy link
Contributor Author

Took off low-hanging-fruit tag. Trying to do this made me think that the Query / QueryClauses stuff should perhaps be refactored...

;)

@dapicester
Copy link

Does it mean that currently is not possible to use OR conditions when querying ActiveModel classes?

@cheerfulstoic
Copy link
Contributor Author

It's certainly possible, you just need to give a string. Something like:

person.as(:p).where("p.age = 20 OR p.age = 30")

@dapicester
Copy link

Of course with a string can write Cypher.

I am trying to write a Neo4j adapter for cancancan (used by rails_admin) so I need to build the query dynamically and I am using ActiveModel methods. Maybe I will try with cypher string ...

@cheerfulstoic
Copy link
Contributor Author

First I'm a bit confused when you say ActiveModel. Do you mean ActiveNode (which uses ActiveModel to access Neo4j nodes)?

If you haven't seen it already, you should look into the Query class from neo4j-core which allows you to build cypher queries via Ruby methods. You can get a fresh query like Neo4j::Session.current.query or you can build one off of ActiveNode like person.association.as_query(:association) or Person.association.as_query(:association), etc...

Also, I've worked on and off to get a neo4j version of rails_admin working here:
https://github.com/cheerfulstoic/rails_admin

It works more or less, I've been trying to get the specs to all pass now.

Great to hear that you're helping to support Neo4j with cancancan!

@dapicester
Copy link

Yes, sorry I mean ActiveNode.

I tried your fork of rails_admin you mentioned on railsadminteam/rails_admin#1377 and more or less it works for me but I have to disable authorizations (basically comment out the config.authorize_with :cancan, RailsAdmin::Ability line). That's why I am trying to add Neo4j support in cancancan.

Of course if I can get something working I will submit PR and let you know.

@dapicester
Copy link

I am reading the Query and QueryClauses, but so far it seems to me that there is no support for the OR clause unless writing Cyper.

What I mean i something similar to this Rails PR where one can write

Article.where(published: true).or(Article.where(secret: true))

or using the where_or syntax

Article.where(published: true).where_or(secret: true)

and get something like

MATCH (n:Article) WHERE n.published = true OR n.secret = true

Do you think can it be (easily) done in the neo4j gem?

EDIT: fixed some typo

@cheerfulstoic
Copy link
Contributor Author

I don't think it will be easily done, unfortunately. I've generated Cyhper OR statements programmatically before, though, so I would suggest seeing if you can do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants