Forum: Ruby on Rails ActiveRecord and Database Views

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Martin G. (Guest)
on 2006-05-03 20:57
(Received via mailing list)
Hiall,

If I have say 10 tables that i would like to wrap up in 1 view to
manipulate data inside these tables, do I then need 10 model.rb files
for all 10 tables plus 1 for the view, or do I just need 1 model.rb
file for the view ?

cheers
Martin
Daniel -. (Guest)
on 2006-05-03 20:57
(Received via mailing list)
You would not use a view for the model as such.

A view is called from a Controller and can be called anything you want.
The
controller method would prepare all the model instances that you
require,
and provide them to either the default view or the view specified.
Martin G. (Guest)
on 2006-05-03 20:57
(Received via mailing list)
Hi Liquid,

I'm not sure you got me right, excuses if I'm wrong. I didn't mean
rails views, but database views, as in "create view blabla as select *
from ..."

cheers
Martin
Daniel -. (Guest)
on 2006-05-03 20:57
(Received via mailing list)
Ok...  Sorri for the misunderstanding
Robby R. (Guest)
on 2006-05-03 20:57
(Received via mailing list)
On May 1, 2006, at 5:03 AM, Martin G. wrote:

> Hiall,
>
> If I have say 10 tables that i would like to wrap up in 1 view to
> manipulate data inside these tables, do I then need 10 model.rb files
> for all 10 tables plus 1 for the view, or do I just need 1 model.rb
> file for the view ?

Only do what you think is necessary. If you're just doing some
reads... you only need the view... assuming that is all the data that
you'll need.

-Robby

Robby R.
Founder & Executive Director

PLANET ARGON, LLC
Ruby on Rails Development, Consulting & Hosting

www.planetargon.com
www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4968 [fax]
Martin G. (Guest)
on 2006-05-03 20:57
(Received via mailing list)
Hi Robby,

If I understand correct this means that if I want the underlying
tables to be updatable via the view, i need to tell ActiveRecord about
the underlying tables i.e. give it model classes, and if I don't need
them updatable then only one model class for the view is sufficient?

As my tables need to be updatable via the view this wouldn't leave me
with less model.rb files I guess :( I was asking this question because
I am a little bit frustrated about the fact that obviously rails needs
one .rb file per model ... which is really polluting my app/models
subfolder and makes files hard to find. (I have about 200 files as I
have that much tables ... If there would be a way to tell rails to
look for more than one model class per .rb file, I would be very
interested in that!!! If I currently try to put more than one model
class per .rb file, rails complains about missing file "modelname.rb"
..

Any opinions?

Martin
Joe M. (Guest)
on 2006-05-03 20:57
(Received via mailing list)
I thought that one could place model files into their class named
folder, so
for example:

/app/models/className/classNameForModel.rb

Maybe I'm mistaken or slightly delusional but likely both o.O  And if it
doesn't work like the stated behavior above ... then it ought to be ;)

Should help you in file soup, at least things would be tucked nicely
away in
their own baggies.

JY
Martin G. (Guest)
on 2006-05-03 20:57
(Received via mailing list)
Hi Joe,

Correct me if I am slightly delusional :) but I can't really follow
your idea. In which way would your suggestion prevent tasteless file
soups? If className is a folder, then which files would you expect
underneath it? I have a table "foos" leading to a class "Foo" ... If I
now have a folder "Foo" below apps/models, which files should I place
there?

Maybe you meant a folder for each controllerName, which would help a
little, but still would be too inflexible in general, imo. All I
really want, is that Rails goes looking for model classes in every .rb
file it finds below app/models, and if it finds 1+ classes per file,
this shouldn't matter. Specifically, it shouldn't be necessary for
model class Foo to reside in app/models/foo.rb, it should be possible
for this class to reside in app/models/bar.rb as well.

Any opinions?

Martin
This topic is locked and can not be replied to.