On 12 January 2011 09:37, Sergio Lombrico <[email protected]> wrote:
> Hi everyone.
>
> I am facing a problem with has_many :through with the following model
> relations:
>
> class User < AR
>  has_one :profile
>  has_many :files, :through => :profile
> end
>
> class Profile < AR
>  belongs_to :user
>  has_many :files
> end
>
> class File < AR
>  belongs_to :profile
> end

I think you might want to reconsider using the name File as this is
already a class in Ruby.  Whether this is the cause of your problem I
don't know, but I would try that first.

Colin

>
> While the call user.files succeeds with no problem, the following
> assignment fails.
>
> f = File.new
> u = User.first
> u.files << f # FAILURE HERE!
>
> Rails spits out a
> ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection
> exception.
>
> Can anyone shed some light on this ?
>
> Cheers,
>
> sergioL
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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 [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to