Hi,

Facing the same problem here but with the simpler case of 
non-polymorphic has_many association. We use the standard 'id' for most 
associations but we also have a 'uuid' field that I need to associate 
on. Using your Company/Review example it would be like this:

companies has a uuid column as uniqe index
reviews has a company_uuid column

Company has_many :reviews, :foreign_key => "company_uuid"

Now, I'd need reviews.company_uuid to join on companies.uuid and not 
companied.id.

Using a new class to set_primary_key is not really an option because 
instantiated Company objects through activerecord finders won't work for 
this association.

Any other suggestions/ideas?

I am working on this right now, I'll keep you posted of my finding.

Colin.

Gregg Pollack wrote:
> Vincey,
> 
>    Thanks for the response.  I've considered using a subclass, which 
> does get around the problem in some circumstance.  Unfortunately in my 
> case, I'm using a polymorphic association.
> 
>    I would need to somehow define a different "type" when the 
> polymorphic association gets stored, because it would store the subclass 
> type as "reviewable_type = Company2".  So I would need some way to 
> override the class name in the polymorphic association.  I haven't found 
> this is possible.
> 
>    I wonder how hard it would be to patch rails to do:
> 
>    has_many :reviews, :as => :reviewable, :with_primary_key => 
> :hr_company_id
> 
> -Gregg
> 
> vincey wrote:
>> I've been struggling with this problem as well. a possible solution to
>> this might be to create a new class for the secondary primary key,
>> something like:
>> 
>> Company2 << Company
>>   set_primary_key :hr_primary_key_id
>> end
>> 
>> and then use Company2 when you want to get the alternate has_many
>> association.
>> 
>> Something else which has occured to me, is that maybe you could use a
>> habtm association.  but then you'd need to make access Company as a
>> join model for this particular operation and you'd need to have
>> something else on the left of it.
>> 
>> not sure how much any of this helps as its purely hypothetical but i'm
>> interested to see where this discussion goes.
>> 
>> Cheers,
>> -vince
>> 
>> 
>> On Jan 22, 6:27 am, Gregg Pollack <[EMAIL PROTECTED]>

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

Reply via email to