Z
Z
zggb2015-04-15 22:46:33
PostgreSQL
zggb, 2015-04-15 22:46:33

Find few id In nested model. postgresql. Real?

On the main page there is a user filter, by the property address (nested for users).
It is performed by a method that first finds real estate within a radius of several kilometers. Then issues users to the controller. After that, user cards with real estate are rendered.
The problem is that one user can have real estate in several cities. And this filter shows an unnecessary city after rendering.
And, for example, a simple search using scope . Vida

User.includes(:real_estates).where("real_estates.address LIKE ?", search).references(:real_estates)

Gives out just what you need. No extra cities.
I don't understand how it works. But is it possible to make the view request work.
User.includes(:real_estates).where("real_estates.id IN (?)", (ID1 or ID2 or ID8)).references(:real_estates)

Where I would indicate the id of houses suitable for the area. Thanks in advance for your advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vsuhachev, 2015-04-16
@zggb

First, study the materiel
. Everything is there, in particular, your request is written like this:

User.includes(:real_estates).where(real_estates: {id: [ID1, ID2, ID8]} )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question