Named scope with has many

Having a problem getting my head round a named_scope problem

I have the following:

class Event < ActiveRecord::Base
has_many :event_alerts
end

class EventAlert < ActiveRecord::Base
belongs_to :event
end

I want to create a named scope that returns only those events that
have event alerts.

But I just can’t seem to get my head around it. This is Rails 2.3 if
that is of importance.

On Mon, Oct 25, 2010 at 9:51 PM, Peter H. <
[email protected]> wrote:

end

I want to create a named scope that returns only those events that
have event alerts.

But I just can’t seem to get my head around it. This is Rails 2.3 if
that is of importance.

Depending on the db you’re using, an EXISTS on the :where clause should
do
the trick.


Erol M. Fornoles
http://erolfornoles.posterous.com
http://github.com/Erol
http://twitter.com/erolfornoles
http://ph.linkedin.com/in/erolfornoles

instead of named scopes use class methods

http://www.railway.at/2010/03/09/named-scopes-are-dead/

On Mon, Oct 25, 2010 at 11:52 AM, Marnen Laibow-Koser
[email protected]wrote:

Radhames Brito wrote in post #956904:

instead of named scopes use class methods

http://www.railway.at/2010/03/09/named-scopes-are-dead/

That article applies only to Rails 3. The OP said he was using Rails
2.3. Therefore, your advice is irrelevant.

not irrelevant as he can use class methods anyway and is are more
flexible,
i posted the link with general info on scopes as you can see the author
praises scopes in rails 2 in the first part of the article and later
explains the good and bad about them along with some guide on how to use
class methods.

Radhames Brito wrote in post #956904:

instead of named scopes use class methods

http://www.railway.at/2010/03/09/named-scopes-are-dead/

That article applies only to Rails 3. The OP said he was using Rails
2.3. Therefore, your advice is irrelevant.

Please read all details before giving advice.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Radhames Brito wrote in post #956940:

On Mon, Oct 25, 2010 at 11:52 AM, Marnen Laibow-Koser
[email protected]wrote:

Radhames Brito wrote in post #956904:

instead of named scopes use class methods

http://www.railway.at/2010/03/09/named-scopes-are-dead/

That article applies only to Rails 3. The OP said he was using Rails
2.3. Therefore, your advice is irrelevant.

not irrelevant as he can use class methods anyway and is are more
flexible,
i posted the link with general info on scopes as you can see the author
praises scopes in rails 2 in the first part of the article and later
explains the good and bad about them along with some guide on how to use
class methods.

Yes. The class method tricks he’s talking about only work with Arel, so
they are irrelevant for a standard installation of Rails 2. Some of his
complaints also seem a bit specious…

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs