MVC design good/bad

Michael G. wrote:

On Jan 19, 2006, at 2:19 , Ben M. wrote:

I see a lot of discussion of the limitations of ActiveRecord on
this

list. Well, there’s nothing saying that you can’t create your model
classes as the domain dictates and have them use the ActiveRecord
objects as (extremely) convenient DAOs.

That sounds interesting. Could you expand on that, or perhaps provide
references to where I might find more information on this?

No, sorry I can’t… cuz I was just theorizing. I don’t know if anyone’s
actually done
this. It would probably be an uphill effort because rails does so much
for you as long as
you “stick to the script”.

I would think that rather than the usual DAO approach, in which the DAOs
query the
database and return an assembled model object, the ActiveRecord might be
good as just a
member variable of the model. You could have a model base class that has
the ActiveRecord
var and the basic delegate methods. The actual instance of ActiveRecord
would be set in
the subclass model object.

Or, you could have a helper, basically a DAO, that creates an
ActiveRecord instance for a
specified table and handles db calls on behalf of the corresponding
model class. This
could be arranged using the “aggregates” approach Eric Evans advocates
in the book Domain
Driven Design. Well, that pattern is intended to control the chaos of
too many classes
talking to too many other classes in a large system. But the “root” of
the “aggregate”
could also be respsonsible in our system for maintaining ActiveRecord
objects for all of
its child objects.

Now, I’m just blundering around here, theorizing off the cuff… so
please take this as
such. Like I said above, the problem with all this is that rails is
based on a merged
domain and data access layer; its one fatal flaw if you ask me… but it
does make small
apps very easy to kick out.

I suspect that someone will want separation of concerns bad enough that
they’ll write a
plugin or module to facilitate using “POROs” (plain old ruby objects)
for the model with
mixins to use whatever data access library you want.

A good first step towards this would be to separate Validations out of
ActiveRecord,
allowing it to be mixed in to model classes. And ActiveRecord should be
a mixin in too. My
model classes don’t have an “is-a” relationship with ActiveRecord.
That’s because
persistence is an orthogonal concern and it should be treated as such!
I’m surprised that
someone like Martin F. hasn’t taken DHH over his knee and spanked
him for this yet.

Ahem. Anyway, once again… these are the ravings of someone who’s read
about three
quarters of the agile book and played with a few examples. Flames
welcome. :slight_smile:

b

On 20-jan-2006, at 18:49, matthew clark wrote:

I think that as Rails grows up from being a simple CRUD front end
flexibility in the data structure is inevitable.

Has Rails ever been “a simple CRUD front end”? Seems people will
always associate Rails with scaffolding…

Don’t let David hear you! :stuck_out_tongue:


Regards, Charles.

No flames from my corner. I really like where this discussion is
leading
to. I think that as Rails grows up from being a simple CRUD front end
flexibility in the data structure is inevitable.

There was a thread less than a week ago about pulling the validations
stuff
out of ActiveRecord, and into a mixin.

http://www.ruby-forum.com/topic/51771#23335

matt

What a ludicrous comment.

On 1/20/06, matthew clark [email protected] wrote:

No flames from my corner. I really like where this discussion is leading
to. I think that as Rails grows up from being a simple CRUD front end
flexibility in the data structure is inevitable.

Tobi
http://jadedpixel.com - modern e-commerce software
http://typo.leetsoft.com - Open source weblog engine
http://blog.leetsoft.com - Technical weblog

Well I don’t think of rails as a simple CRUD front end, but I do think
having to make all
you domain classes subclass a framework class is short-sighted.

Ironically, this is one of the things complain about struts for: it
depends heavily on
subclassing. And, when I described ActiveRecord to my co-worked, his
eyes lit up and he
said, “a-hah… they’ve come up with their own EJB CMP!” (although
obviously without all
the deployment descriptors).

And I think this “simple CRUD front end” urban lengend is just the first
of a host of
annoying associations rails will be pegged with…

b

On Jan 21, 2006, at 10:38 AM, Ben M. wrote:

And I think this “simple CRUD front end” urban lengend is just the
first of a host of annoying associations rails will be pegged with…

b

There is nothing about the way rails works that forces you to use a

subclass of ActiveRecord as your domain models. Most of the models I
use for the newspaper website I wrote are in fact just custom ruby
interfaces to proprietary Baseview databases that a lot of newspapers
use.

In fact you could just as easily use dbi or whatever you want for

your model files. ActiveRecord is of course the nicest way to do
models in rails right now since the framework makes it so easy to
work with but you can use anything you want as your model

Cheers-
-Ezra Z.
WebMaster
http://yakimaherald.com
Yakima Herald-Republic Newspaper
[email protected]
509-577-7732

ActiveRecord is of course the nicest way to do
models in rails right now since the framework makes it so easy to
work with but you can use anything you want as your model

Of course you can, and you can even throw away all the rails code and
rewrite it from scratch. The thing people are talking about that it
should be easy to use non-AR models, while still enjoying standard
validations, type casting etc.

BTW, I think besides validations, there are two other important areas:
type casting and relationships (belongs_to etc).

The lack of type casting for custom attributes hurts most when you e.g.
want a non-persisted date field in your AR model. While the fields
coming from DB can automatically assemble a date from year-month-day
parts and have other nice things, when using custom attributes you’re on
your own.

Whether and how belongs_to, has_many etc can be used for custom models
is much less clear. I think there should be a way of customizing how
related rows are fetched even for AR models, and probably this will work
for non-AR models too.