On 25 April 2014 08:59, [email protected] <[email protected]> wrote:
> On Thursday, April 24, 2014 5:35:08 PM UTC+2, Colin Law wrote:
>>
>> For those of us with less knowledge of how the internals of rails
>> works could you provide a simple example of what you are attempting to
>> achieve with dynamic class name in a association?
>
>
>  I can't speak for the OP, but in my case I needed something like:

Since you did not quote a previous message then the assumption is that
you are the OP.

>
> class Report < ActiveRecord::Base
>   has_many :reports_subjects
>   has_many :subjects, through: :reports_subjects, class_name: ->(report) {
> report.subjects_type }
>
>   def subjects_type
>     # divine required subject model class somehow
>   end
> end
>
> Of course, that won't fly since the class_name is evaluated purely as a
> string deep down in the reflection and at that point, all knowledge of the
> specific instances involved in an association has been discarded.

What I don't understand is why you would want to do that.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtZ-9OZA%3DkFDmfncKvRWtQNc%3DOPLOU__Ss0YtJceqzr0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to