3 ms·
> I remember when foreign keys were taboo among Rails developers because Rails didn't have a way to express them in its DSL. What? Relationships (and thus fore
by krainboltgreene 8y ago
> I remember when foreign keys were taboo among Rails developers because Rails didn't have a way to express them in its DSL.
What? Relationships (and thus foreign keys) have been around since before 1.2.
- pmontra 8y agoRelationships are not foreign keys. Relationships (has_many, belongs_to) are a Rails construct. Foreign keys are a database thing. I started using Rails almost at the very beginning. See https://stackoverflow.com/questions/2373262/are-foreign-keys-in-rails-generally-avoided https://stackoverflow.com/questions/2373262/are-foreign-keys... from 2010 for a bunch of links to DHH opinion on the matter (from 2006.) Foreign keys made it into the DSL with Rails 4.2 http://guides.rubyonrails.org/4_2_release_notes.html#foreign-key-support http://guides.rubyonrails.org/4_2_release_notes.html#foreign... https://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/add_foreign_key https://apidock.com/rails/ActiveRecord/ConnectionAdapters/Sc... Before that we were using gems or writing SQL into the up and down migrations. https://robots.thoughtbot.com/referential-integrity-with-foreign-keys https://robots.thoughtbot.com/referential-integrity-with-for... (from December 2014)
- krainboltgreene 8y agoJust to be clear, you keep saying "foreign key", but the phrase most people know is "foreign key constraint" (because it's just a constraint).