Hi

On Thu, May 19, 2016, at 19:21, Johnny Stewart wrote:
> I have changed the primary key on a table “statuses”  to now be
> entity_id
> 
> In my status model I have:
> 
> self.primary_key = 'entity_id'
> 
> when I try to render a collection of comments associated with a status
> like so:
> 
> <%= render @comments %>
> 
> I get this error:
> 
> PG::UndefinedColumn: ERROR:  column comments.status_id does not exist
> LINE 1: SELECT "comments".* FROM "comments" WHERE "comments"."status_id"
> 
> I'm assuming when the above call is constructed by rails it is assuming
> the table statuses has primary key status.id by convention..
> 

All it does is taking the model name and suffix it with _id. Specifying
:foreign_key option should work.

:foreign_key
    Specify the foreign key used for the association. By default this is
    guessed to be the name of this class in lower-case and “_id”
    suffixed. So a Person class that makes a has_and_belongs_to_many
    association to Project will use “person_id” as the default
    :foreign_key.

http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

-- 
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/1463654118.1310528.612451025.6CCE288F%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to