News for hackers. Stuff that matters.
Re:ORMs don’t kill databases. Developers do. by trebor on Tuesday August 30, 2011 @09:36AM (#2941344)
One Rails project I had got sidelined for a good 6 hours because ActiveRecord requires IDs on everything. The documentation says that you can skip IDs, but when you try to save it crashes every time.

Go figure whose fault that one is.

Re:ORMs don’t kill databases. Developers do. by rahoulb on Tuesday August 30, 2011 @10:05AM (#2941464)
I'm interested - where did you learn that ActiveRecord does not require IDs?

The only case where I can think of where it doesn't require IDs is when building a join table (for a many-to-many relationship).

In every other case, you need to specify a primary key field (although it does not need to be an auto-incrementing integer called "id") and I'm sure it says as much in the docs.

EDIT: You can do a select and omit the ID field in the resultset, but you cannot save the results back again - simply because it does not know where to write it back. Again, I'm pretty sure I remember reading that in the docs, but I may have imagined it.

Re:ORMs don’t kill databases. Developers do. by trebor on Tuesday August 30, 2011 @01:17PM (#2942311)
http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAd...

    create_table(:categories_suppliers, :id => false) do |t|
      t.column :category_id, :integer
      t.column :supplier_id, :integer
    end
I did this and indexed the table by date, and it works for everything except saving a record. Like I said, an ID/primary key is required though that section of the documentation implies that an ID is optional.
Re:ORMs don’t kill databases. Developers do. by rahoulb on Tuesday August 30, 2011 @03:45PM (#2942951)
Hmm - yeah the docs are sort of unclear, if you're not familiar with the convention.

:categories_suppliers implies that the table is a join table (a many-to-many join between categories and suppliers) - which is why it has no ID and why it only has the two foreign key fields with no other data.

Re:ORMs don’t kill databases. Developers do. by trebor on Tuesday August 30, 2011 @06:41PM (#2943539)
Yet the assumption that all models require an ID is a fallacy. I was generating reports unique to the day, therefore a simple Date field was adequate as an index/ID. I don't know about other ORMs but when working directly with the SQL it'd be no issue.

I hold out that it's a problem in the design of ActiveRecord to assume that there will always be a primary key. That said, if I can just tell the model "identify yourself by this key" WITHOUT setting it as the primary key I would be happy.

Re:ORMs don’t kill databases. Developers do. by trebor on Tuesday August 30, 2011 @01:12PM (#2942296)
Are you saying that because I didn't set the date field as my primary key, it crashed?