-
Notifications
You must be signed in to change notification settings - Fork 95
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
Fix #geo_scope on a model with acts_as_mappable :through
(rebased)
#26
base: master
Are you sure you want to change the base?
Conversation
Basically, for a model which does this: acts_as_mappable :through => :some_column queries using geo_scope automatically :include :some_column. In a related vein, calling #geo_scope on a model now returns a special scope object (ActsAsMappable::Relation instead of ActiveRecord::Relation) such that if you call another scope method such as `where`, `order`, etc. and attempt to refer to a "distance" column, that "distance" will automatically be replaced with the Haversine formula in your query. No more HAVINGs or subqueries!!
Hi But it is not working. |
Okay, in what way does it not work? What's the error that you're getting? |
actually the back end query is not working. |
Isn't your table named "users", rather than "user"? i.e. it should be
|
Yes table name is users by mistake i had type it user . But the problem remains same . If u run the above query then the geo_scope method function will not work.It will run a different query in the back end. |
Okay so what is the error that you're getting when you run the first query? Sorry to keep asking questions but I still don't quite know what the issue is here. |
actually there is no error i am getting but the problem is the actual query running in the back end is different. the geo_scope method is not working there. |
Okay, can you give me:
|
The actual query running in the back end SELECT But the query should be . Which can be achievable by writing But in that case the the effectiveness of "includes" will be lost. |
And i under stand the basic difference between include and joins but is the any way to write the same query using joins. |
Got it. Thanks for that. I'll take a look at why that is not working and get back to you. |
Thanks Elliot . it will be great if geo_scope will work for both include and joins. |
Hi Elliot is there any modification in geo_scope. is it working now with include. |
No... I didn't make any changes... that's interesting.... and you didn't make any changes either? |
Yes i have written the code in different way. I am using join instead of include. But it will be really help full if i can use include feature. |
Oh I'm sorry I misread, I thought you said it suddenly started working. No, I have yet to fix this. I am a little busy right now with work and whatnot, but I will let you know when I've fixed this. |
This branch supercedes #8 and is up to date with master.
Again, I took the liberty of ensuring that the tests pass for all adapters I have available (postgresql, mysql, sqlite).
Unfortunately I don't have a real-world app to test these changes on. Can someone do this for me? These changes could be potentially breaking and I want to make sure all the kinks are ironed out.
Edit: If you are too lazy to read the commit messages, an important change that 1d024ca makes is to modify #geo_scope so that it returns not the usual ActiveRecord::Relation object (which is what a scope object is), but an ActsAsMappable::Relation object. This object is special in that you add a
where
ororder
clause and you refer to a "distance" column, it will be replaced with the distance calculation formula (probably the Haversine formula unless you have set it to something else). However, this only works if you addwhere
ororder
after you saygeo_scope
. For instance, this will work:but this will not:
What I want to know is whether you think this will be a problem. For instance, I could change it so that #geo_scope takes a block:
This implies that #geo_scope does something special. However, it may be too cumbersome for people.