title: Rails pgsql error: No operator matches the given name and argument type(s) with many-to-many
body: <p>I'm running Rails 4 on postgresql 9.3, I'm implementing the following many-to-many relationship</p>
  
  <p>first model:</p>
  
  <pre><code>class Cms::ContentEntry &lt; ActiveRecord::Base
    self.table_name = 'cms_content_entries'
  
    has_many :entries_media, class_name: 'Join::EntryMedia', foreign_key: :cms_content_entry_id
    has_many :media_items, through: :entries_media, class_name: 'Media::Item', source: :media_item
  end
  </code></pre>
  
  <p>join model:</p>
  
  <pre><code>class Join::EntryMedia &lt; ActiveRecord::Base
    self.table_name = 'join_entries_media'
  
    belongs_to :entry, class_name: 'Cms::ContentEntry'
    belongs_to :media_item, class_name: 'Media::Item'
  end
  </code></pre>
  
  <p>second model:</p>
  
  <pre><code>class Media::Item &lt; ActiveRecord::Base
    self.table_name = 'media_items'
  
    has_many :entries_media, class_name: 'Join::EntryMedia', foreign_key: :media_item_id
    has_many :entries, through: :entries_media, class_name: 'Cms::ContentEntry', source: :entry
  end
  </code></pre>
  
  <p>But in the script console, when I run: </p>
  
  <pre><code> Cms::ContentEntry.last.media_items
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code> SELECT "media_items".* FROM "media_items" INNER JOIN "join_entries_media" ON    
   "media_items"."id" = "join_entries_media"."media_item_id" WHERE  
   "join_entries_media"."cms_content_entry_id" = $1  [["cms_content_entry_id", 2]]
    PG::UndefinedFunction: ERROR:  operator does not exist: uuid = integer
    LINE 1: ...R JOIN "join_entries_media" ON "media_items"."id" = "join_en...
                                                           ^
    HINT:  No operator matches the given name and argument type(s). You might need to 
    add explicit type casts.: SELECT "media_items".* FROM "media_items" INNER JOIN
    "join_entries_media" ON "media_items"."id" = "join_entries_media"."media_item_id"
    WHERE "join_entries_media"."cms_content_entry_id" = $1
  </code></pre>
  
  <p>Here's how my schema looks like:</p>
  
  <pre><code>CREATE TABLE cms_content_entries (
      id integer NOT NULL,
      author_id integer,
      title character varying(255),
      body text,
      metadata hstore,
      published_at timestamp without time zone,
      created_at timestamp without time zone,
      updated_at timestamp without time zone
  );
  
   CREATE TABLE join_entries_media (
      id integer NOT NULL,
      cms_content_entry_id integer,
      media_item_id integer
  );
  
   CREATE TABLE media_items (
       id uuid DEFAULT uuid_generate_v4() NOT NULL,
       element_id bigint,
       element_type character varying(255),
       created_at timestamp without time zone,
       updated_at timestamp without time zone,
       user_id integer
  );
  </code></pre>