5 ms·
You forgot to add an index on tags.name and null constraints on the rest of the columns. > from there it's just regular rails That's the problem. Examples lik
by davidcuddeback 7y ago
You forgot to add an index on tags.name and null constraints on the rest of the columns.
> from there it's just regular rails
That's the problem. Examples like this focus on the first few minutes of development. Not the subsequent years of maintenance.
- localhostdotdev 7y agoI stayed close to what the author did. adding an index: add_index :tags, :name adding a null constraint: change_column :tags, :name, :string, null: false validates :name, presence: true # for proper validations https://github.com/localhostdotdev/bug/commit/3765237008c36c539b30cbc8ad4127c14b0e546b https://github.com/localhostdotdev/bug/commit/3765237008c36c...
- davidcuddeback 7y ago> I stayed close to what the author did. Fair enough. I’ll concede that wasn’t a fair comparison to the OP. My point remains that examples focusing on the initial setup are uninteresting (to me) because that’s not where the bulk of the work is.
- blueplanet200 7y agoRails is also fine to maintain down the road. Certainly easier than any data layer most engineers would make by hand.
- vinceguidry 7y ago> Not the subsequent years of maintenance. You're gonna have to pry the Rails from my cold dead fingers if you want me to maintain a web app's database abstraction layer long-term. No other tool works half as well as ActiveRecord. You could maybe convince me to try out https://rom-rb.org/ https://rom-rb.org/ but only on a brand new project and only if Rails isn't appropriate. If it's a project that wasn't built with Rails, I'm going to want https://github.com/jeremyevans/sequel https://github.com/jeremyevans/sequel if ActiveRecord is too much trouble to introduce.
- oogway8020 7y agoI have been lucky to be able to pick what I want to use, so I pick non-rails stack (Sinatra/Padrino and now Roda + Sequel). No other tool works as half as Sequel. You're gonna have to pry Sequel from my cold dead fingers.
- vinceguidry 7y agoDon't get me wrong, I love Sequel. But ActiveRecord is far more polished. And that starts to matter once you start needing to go 'off-script'.
- djupblue 7y agoAdding an index on tags.name is likely not very useful on its own but adding an index with an uniqueness constraint to prevent duplicates is probably a good idea. Assuming there are just a few different tags records (<1000) then a sequential scan is generally either insignificantly slower or even faster than an index scan. >Not the subsequent years of maintenance. I'd much rather maintain this example than a code base replicating the same behavior without an ORM.