Forum: Ruby on Rails Active Record HELP!!!!!

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.
Phillip Novess (Guest)
on 2006-05-09 20:23
(Received via mailing list)
Hello,

Can someone kindly tell what the heck creating a relationship does in
active record?

I understand the idea of joining the tables and such. But how do I use
it? Is it available in a scaffold? How about when I want to view a
record and want to see all the joined data from the other table?  Do I
have to manually code the data I want from the other table? Does this
automatically make the linked data available in the data object?

Can we get real docs instead of API refs?

Thanks,
Phill
Stephen B. (Guest)
on 2006-05-09 20:32
(Received via mailing list)
I'm sure i speak for everyone when i *highly* recommend that you have a
look at getting the Agile book:
http://www.pragmaticprogrammer.com/titles/rails/index.html.

It'll give you a good grounding in Rails and the concepts behind things
like Active record.

Steve
Vince P. (Guest)
on 2006-05-09 21:06
(Received via mailing list)
https://addons.mozilla.org/firefox/1843/

>From the site:

FireBug lets you explore the far corners of the DOM by keyboard or
mouse.
All of the tools you need to poke, prod, and monitor your JavaScript,
CSS,
HTML and Ajax are brought together into one seamless experience,
including
an error console, command line, and a variety of fun inspectors.

Visit the FireBug website for documentation, screen shots, and
discussion
forums:

http://www.joehewitt.com/software/firebug/

A quick overview of FireBug's features:

* Status bar icon shows you when there is an error in a web page
* A console that shows errors from JavaScript and CSS
* Log messages from JavaScript in your web page to the console (bye bye
"alert debugging")
* An JavaScript command line (no more "javascript:" in the URL bar)
* Spy on XMLHttpRequest traffic
* Inspect HTML source, computed style, events, layout and the DOM

Works with:
    Firefox     1.5 - 3.0     ALL
Robert J. (Guest)
on 2006-05-09 21:50
(Received via mailing list)
You might want to start by looking at this screencast:

http://media.rubyonrails.org/video/rails_take2_wit...

Robert
Phillip Novess (Guest)
on 2006-05-09 21:53
(Received via mailing list)
Thanks. But that really doesn't help. I have the book.  I don't see
anything that clearly states what s the result of linking the tables.

Are the columns from say table A available when I view a record from
table B that references table A?

Is my object now B.column1, B.column2, B.column3, A.column1 or what? If
NOT then what's the point of creating the link?

Thanks,
Phill




On May 9, 2006, at 10:32 AM, Stephen B. wrote:

I'm sure i speak for everyone when i *highly* recommend that you have a
look at getting the Agile book:
http://www.pragmaticprogrammer.com/titles/rails/index.html.

It'll give you a good grounding in Rails and the concepts behind things
like Active record.

Steve

Phillip Novess wrote:
> Phill
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
Kenneth L. (Guest)
on 2006-05-09 22:14
(Received via mailing list)
See pages 233 and 237, they spell it out pretty clearly.

Ken
Derrick S. (Guest)
on 2006-05-09 22:14
(Received via mailing list)
I don't mean to sound rude, but you state that you have the book ...
have you read it?  Furthermore, have you ever built a database
application before?  Please don't take offense, but if you answered
no to these questions, then I think you'll have some homework to do
before you are ready to dive into building a rails app.

It is stated quite clearly in the book, as well as the docs, that the
result of declaring an association in a model is that the elements in
the related model become available as methods of the class instance.
The method will access a single object for belongs_to or has_one
relationships, and an array of objects for has_many relationships.

One last thing - You'll get faster and more appropriate responses if
you make your subject line meaningful.  Especially on lists as busy
as this, generic subjects will be glossed over more often than not.


-Derrick S.
Stephen B. (Guest)
on 2006-05-09 22:17
(Received via mailing list)
You should be able to access a parent via a child object.  For example:

class Parent < ActiveRecord::Base
    has_many :children
end

class Child < ActiveRecord::Base
   belongs_to :parent
end

The 'children' table would have 'parent_id' column referencing the
'parents' table.

You can then reference the parent via the child:

child = Child.find(1)
child.parent.name -----> shows the parent's name

The book does explain all this, but you may have to read through every
page as it's not really a reference book (imo).  The Rails recipes book
looks quite promising for a problem/solution approach.

Hope this helps,

Steve
Phillip Novess (Guest)
on 2006-05-09 23:46
(Received via mailing list)
Thanks. That makes sense.  child.parent.name.  Ah ha.

Thanks,
Phill



On May 9, 2006, at 12:13 PM, Stephen B. wrote:

You should be able to access a parent via a child object.  For example:

class Parent < ActiveRecord::Base
    has_many :children
end

class Child < ActiveRecord::Base
   belongs_to :parent
end

The 'children' table would have 'parent_id' column referencing the
'parents' table.

You can then reference the parent via the child:

child = Child.find(1)
child.parent.name -----> shows the parent's name

The book does explain all this, but you may have to read through every
page as it's not really a reference book (imo).  The Rails recipes book
looks quite promising for a problem/solution approach.

Hope this helps,

Steve

Phillip Novess wrote:
> a look at getting the Agile book:
>> a record and want to see all the joined data from the other table?
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
Phillip Novess (Guest)
on 2006-05-09 23:46
(Received via mailing list)
Derrick,

Yeah I've made my living building web applications for the past 8
years.  However, I use PHP and Oracle on a daily basis NOT Rails. I
don't think anybody would argue that there is anything quite like
Rails.  That's what makes it interesting.

Also. I'm doing this in addition to my daily work in PHP so I get a
little confused.  Ruby is 100% object oriented, PHP is not. I'm still
trying to sink my head around that concept alone.  So please bare with
me. Sometimes I just need to ask what is meant by something otherwise
what's the point of a list right?

I guess I'm spoiled with the excellent documentation resources at
php.net.

Thanks for the help. Very good points.

Thanks,
Phill

On May 9, 2006, at 12:13 PM, Derrick S. wrote:

I don't mean to sound rude, but you state that you have the book ...
have you read it?  Furthermore, have you ever built a database
application before?  Please don't take offense, but if you answered no
to these questions, then I think you'll have some homework to do before
you are ready to dive into building a rails app.

It is stated quite clearly in the book, as well as the docs, that the
result of declaring an association in a model is that the elements in
the related model become available as methods of the class instance.
The method will access a single object for belongs_to or has_one
relationships, and an array of objects for has_many relationships.

One last thing - You'll get faster and more appropriate responses if
you make your subject line meaningful.  Especially on lists as busy as
this, generic subjects will be glossed over more often than not.


-Derrick S.


On May 9, 2006, at 1:48 PM, Phillip Novess wrote:

> Phill
> It'll give you a good grounding in Rails and the concepts behind
>> a record and want to see all the joined data from the other table?
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
This topic is locked and can not be replied to.