Constructing an array of objects from an array of objects

On line 1 I have constructed an array of Event objects, which belong_to
an Account object. How might I construct an array of Account objects
from this array of Event objects on line 2?

1 notices = Event.find(:all, :conditions => [“account_id IN (?) AND name
= ?”, self.account_ids, account_notice_sent’])
2 return notices.account

Use collect:

accounts = notices.collect{|n| n.account}

You may want to add :include => ‘account’ to your Event.find to eager
load the accounts.

Peter M. wrote:

On line 1 I have constructed an array of Event objects, which belong_to
an Account object. How might I construct an array of Account objects
from this array of Event objects on line 2?

1 notices = Event.find(:all, :conditions => [“account_id IN (?) AND name
= ?”, self.account_ids, account_notice_sent’])
2 return notices.account


Sincerely,

William P.

Exactly what I was looking for. Thanks William :slight_smile: