Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try to also set the primary key:</p> <pre><code>class FeatureAttribute &lt; ActiveRecord::Base set_table_name 'feature_attribute' set_primary_key 'feature_id' belongs_to :feature end </code></pre> <p><strong>UPDATE</strong></p> <p>I think your problem lies anywhere else. I just tested and ActiveRecords works fine with tables without a primary key:</p> <p>For a simple table:</p> <pre><code>class CreateThings &lt; ActiveRecord::Migration def change create_table :things, :id =&gt; false do |t| t.string :name t.timestamps end end end </code></pre> <p>in console:</p> <pre><code>Loading development environment (Rails 3.1.1) irb(main):001:0&gt; Thing.create(:name=&gt;'A name for the thing') (0.1ms) BEGIN SQL (0.3ms) INSERT INTO `things` (`created_at`, `name`, `updated_at`) VALUES ('2011-11-02 16:33:48', 'A name for the thing', '2011-11-02 16:33:48') (40.3ms) COMMIT =&gt; #&lt;Thing name: "A name for the thing", created_at: "2011-11-02 16:33:48", updated_at: "2011-11-02 16:33:48"&gt; irb(main):002:0&gt; Thing.first Thing Load (0.7ms) SELECT `things`.* FROM `things` LIMIT 1 =&gt; #&lt;Thing name: "A name for the thing", created_at: "2011-11-02 16:33:48", updated_at: "2011-11-02 16:33:48"&gt; irb(main):003:0&gt; </code></pre> <p><strong>UPDATE 2</strong> Not very fine:</p> <pre><code>irb(main):003:0&gt; Thing.create(:name=&gt;'Another thing') (0.2ms) BEGIN SQL (0.4ms) INSERT INTO `things` (`created_at`, `name`, `updated_at`) VALUES ('2011-11-02 16:40:59', 'Another thing', '2011-11-02 16:40:59') (35.4ms) COMMIT =&gt; #&lt;Thing name: "Another thing", created_at: "2011-11-02 16:40:59", updated_at: "2011-11-02 16:40:59"&gt; irb(main):004:0&gt; Thing.first Thing Load (0.5ms) SELECT `things`.* FROM `things` LIMIT 1 =&gt; #&lt;Thing name: "A name for the thing", created_at: "2011-11-02 16:33:48", updated_at: "2011-11-02 16:33:48"&gt; irb(main):005:0&gt; Thing.last Thing Load (11.8ms) SELECT `things`.* FROM `things` ORDER BY `things`.`` DESC LIMIT 1 Mysql2::Error: Unknown column 'things.' in 'order clause': SELECT `things`.* FROM `things` ORDER BY `things`.`` DESC LIMIT 1 ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'things.' in 'order clause': SELECT `things`.* FROM `things` ORDER BY `things`.`` DESC LIMIT 1 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload