Friday, June 3, 2011

[Rails] Re: There must be a more elegant way to do this

Thank you all for your suggestions.

My apologies, I should have mentioned this before but I thought once I
figure out how to get uniq records based on combination of user_id and
address_id I could figure out the rest. Essentially amongst other
fields, each of these records contains a computed distance field i.e.
how far is that user/address from a point. That distance could be
different so while user_id and address_id could be same other fields
may not be same.

What I need to do is get unique user_id/address_id records with the
shortest distance.

Thanks again!
-S

On Jun 3, 12:27 pm, Tim Shaffer <timshaf...@me.com> wrote:
> On Friday, June 3, 2011 3:09:55 PM UTC-4, pavling wrote:
>
> > On 3 June 2011 19:19, Tim Shaffer <timsh...@me.com> wrote:
> > > I think the problem with doing that is that the arrays contain instances
> > of
> > > models.
>
> > I .uniq arrays of instances of models all the time - it's a very handy
> > tool.
>
> Agreed, but it doesn't solve the problem when you only want unique instances
> based on *some* of the fields.
>
> > > Sounds like skt wants to consider an instance unique based on only two
> > > attributes of each instance.
>
> > If so, then collecting up just those values and .uniq on them would
> > still be readable, as a one liner or broken into a couple, or doing a
> > .group_by and checking the size of the hash....
>
> Agreed once again, but that only gets you the unique address_ids and
> user_ids, not the full instances. Not sure if that would matter for his
> requirements
>
> Cheers!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate