Ruby on Rails Sunday, October 2, 2011

On 3 October 2011 02:57, Rodrigo <joserodrigofuentes@gmail.com> wrote:
> I want to find all records in a model that contains the email
> "john@test.com" despite the fact that the email value is within an
> array of hashes. How do I do this?

You should probably change the array of hashes to an array of AR associations,

> The email.rb model file says:
>
> class Email < ActiveRecord::Base
>
>  has_many :from_addresses, :class => "EmailAddress"
>  has_many :to_addresses, :class => "EmailAddress"
>  has_many :cc_addresses, :class => "EmailAddress"
>
> end

So that the EmailAddress model implements all the keys of your old
hashes as attributes, and you can then use regular finders.

--
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.

No comments:

Post a Comment