2

How can I get my plucked array to work with the paginate method (which I believe only works on queryproxy objects)

My results are pulling up a few of the same nodes as there are multiple paths to it, so I added pluck and distinct like so..

current_user.friends....where()...params().pluck('DISTINCT e').paginate..

Is there another way around it? or would a change have to be made in the neo4j paginate gem?

Clam
  • 935
  • 1
  • 12
  • 24
  • What does your `friends` association look like? If it only specifies one relationship type you should only get distinct results. Are there sometimes multiple copies of a relationship between users? – Brian Underwood Jan 12 '15 at 21:14
  • Right now, I don't think you can. The pagination is pretty limited and needs to be extended to support this. – subvertallchris Jan 12 '15 at 23:06
  • there's other stuff past friends, that's why there's multiple paths to get to the node. I just shortened it. maybe i can look at the gem... it's probably outside of something i know how to do – Clam Jan 12 '15 at 23:35

1 Answers1

2

Right now, this isn't doable using the paginate method. WillPaginate returns WillPaginate::Collection objects that are already populated from the database. We might be able to make it return something else and evaluate lazily but I'd have to play around with it more.

You can create Neo4j::Paginated objects directly, but these are just plucked results from QP.

# match stupid friends with awful events, return distinct events
query = current_user.friends(:f).where(stupid: true).events(e:).rel_where(expected_attendees: 0)
@bad_events = Neo4j::Paginated.create_from(query, 1, 15).pluck('distinct e')

create_from returns a Neo4j::Paginated object that delegates each and pluck to its the QueryProxy object fed to it. Note that it's going to paginate based on the end of the chain, so it's doing the first page with 15 per page based on the events. Also note that you can't do a distinct count.

Check https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/paginated.rb for more. It's pretty easy to read.

subvertallchris
  • 5,282
  • 2
  • 25
  • 43