-1

I have been learning Rails since this summer and have written some successful standalone apps with it, and really have grown to appreciate nearly everything about Rails.

However, my current project is writing Rails as a front-end to a database that will be used for other things (web services, data warehouses, other apps connecting) -- and I am realizing that ActiveRecord, and largely all the Rails developed around AR, seem to be very one directional when it comes to this approach.

Note: I am not referring to a Legacy database, ie. one that we have to plug into, but was designed "back in the day"..

Rails seems to think it is, and should be, the only application working with this data. I am noticing it more and more when it comes to things like, composite primary keys (which is something you cannot just adjust, like table naming and column naming).

While I know there is a composite key gem, I feel like I am developing an entire MVC application dependent on this single gem working. I fear I will run into more and more things like that. I have looked into alternative ORM's, however it seems that many gems depend on ActiveRecord.

I guess I am a bit surprised and saddened at this apparently selfish angle that ActiveRecord has.

Anyone have any feedback or success about how Rails works with an enterprise level database?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Atari2600
  • 1,219
  • 2
  • 13
  • 26

1 Answers1

3

Rails is built primarily as an "opinionated" web development framework.

What it is built to do out-of-the-box is full-stack web applications, where the entire system is built the "Rails way", which is the result of many decisions made by committers to Rails to keep the system simple and standard. The number of configuration decisions that need to be made are very small when you stick to the conventions.

These conventions include setting up your databases in a certain way. Primary keys are auto-increment and named 'id', foreign keys are 'foreigntable_id'. ActiveRecord is built-in and almost always assumed to be used (even when it isn't).

None of this means that straying from the standard stack won't work. Sequel and DataMapper work just fine. You can name your table columns (nearly) anything you want. If your application can do what it is supposed to do; that is the most important thing.

Yes, because you used Datamapper, now your app depends on Datamapper. How is that a bad thing?

Understand that because ActiveRecord is the default, that many other gems build on ActiveRecord to do their thing, so they may not work with Datamapper. That is not Datamapper's fault (or Rails').

The real question here, is "Is Rails, even when you use an alternative ORM or the composite keys gem, still more suitable and productive than X?"

I would argue that it is. So what that I have to set self.table_name= and self.primary_key= in every class? So what if I have to be forgo some gems that only work with ActiveRecord? So what if you have to consider database triggers and views. I deal with all these things, and Rails is still a joy to work with compared to everything else I've ever used.

Unixmonkey
  • 18,485
  • 7
  • 55
  • 78
  • I appreciate your feedback. Being new to the Rails world, I am just intimidated by replacing what seems to be a core element (ActiveRecord) - or using a gem that may or may not be updated? Do you personally feel like replacing the ORM is a better bet for a situation where the database is built outside of rails? – Atari2600 Feb 05 '13 at 15:50
  • 1
    @JasonB I have always just used ActiveRecord, but I checked out Datamapper awhile ago, and could see where it may really help you with a very legacy-ish db. – Unixmonkey Feb 05 '13 at 16:04
  • I guess that's my hangup, as this database will be anything but legacy. Its brand new, and being designed along side the rails app, but it has to stand on its own, so other systems can connect to it. I am having problems getting the composite_key gem to work, which is why I asked. – Atari2600 Feb 05 '13 at 16:08