Em 13-08-2012 21:49, Rafael Almeida escreveu:
On Sunday, August 12, 2012 12:06:00 AM UTC-3, Matt jones wrote:
On Aug 11, 2012, at 6:23 PM, Rafael Almeida wrote:
On Friday, August 10, 2012 5:50:58 PM UTC-3, EMoreth wrote:
Try this:
On Sunday, August 12, 2012 12:06:00 AM UTC-3, Matt jones wrote:
On Aug 11, 2012, at 6:23 PM, Rafael Almeida wrote:
On Friday, August 10, 2012 5:50:58 PM UTC-3, EMoreth wrote:
Try this:
Project.joins(:services).where(:services = { :id = [1,2]
}).group(:id).having(count(*) =
On Aug 11, 2012, at 6:23 PM, Rafael Almeida wrote:
On Friday, August 10, 2012 5:50:58 PM UTC-3, EMoreth wrote:
Try this:
Project.joins(:services).where(:services = { :id = [1,2]
}).group(:id).having(count(*) = 2).all
This produces to me:
SELECT `projects`.* FROM `projects` INNER JOIN
On Friday, August 10, 2012 5:50:58 PM UTC-3, EMoreth wrote:
Try this:
Project.joins(:services).where(:services = { :id = [1,2]
}).group(:id).having(count(*) = 2).all
This produces to me:
SELECT `projects`.* FROM `projects` INNER JOIN `services` ON
`services`.`project_id` =
On Aug 11, 2012, at 6:23 PM, Rafael Almeida wrote:
On Friday, August 10, 2012 5:50:58 PM UTC-3, EMoreth wrote:
Try this:
Project.joins(:services).where(:services = { :id = [1,2]
}).group(:id).having(count(*) = 2).all
This produces to me:
SELECT `projects`.* FROM `projects` INNER
Try this:
Project.joins(:services).where(:services = { :id = [1,2]
}).group(:id).having(count(*) = 2).all
This produces to me:
SELECT `projects`.* FROM `projects` INNER JOIN `services` ON
`services`.`project_id` = `projects`.`id` WHERE `services`.`id` IN (1, 2)
GROUP BY id HAVING count(*) = 2
Isn't the case where a simple group by X having count(*) = 2 could handle
the problem ?
Arel can achieve this query easily.
On Wed, Aug 8, 2012 at 2:27 PM, Pedro Nascimento pnascime...@gmail.comwrote:
Take a look at ARel and Squeel gem. Squeel gem supports something like
this already.
On
I studied Squeel a bit, the best I could do was this:
Person.joins{services}.where{
id.in(Person.joins{services}.where{services.type == 1}.select{id})
id.in(Person.joins{services}.where{services.type == 2}.select{id})}
which is both unefficient and very ugly.
I think it would
Unless I misunderstood you, I think that would only work if there were only
2 possible service types and I grouped by person_id. I have something a
little more general in mind.
On Thursday, August 9, 2012 9:26:24 AM UTC-3, EMoreth wrote:
Isn't the case where a simple group by X having
Sorry for the double post, but I came up with arel:
people.project(:id).join(services).on(services[:person_id].eq(people[:id])).where(services[:type].eq(1)).intersect(
people.project(:id).join(services).on(services[:person_id].eq(people[:id])).where(services[:type].eq(2)))
calling
Hello.
Let's say I have the following schema
People --- people_services --- services
That is, people has a many-to-many relationship with services. Say I want
to find all people who has services of types 1 and 2. How can we do it on
activerecord today?
My best solution so far is this
Take a look at ARel and Squeel gem. Squeel gem supports something like this
already.
On Wed, Aug 8, 2012 at 12:05 PM, Rafael Almeida almeida...@gmail.comwrote:
Hello.
Let's say I have the following schema
People --- people_services --- services
That is, people has a many-to-many
12 matches
Mail list logo