[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Web Databases and Objects

John Joyce

7/14/2007 2:45:00 AM


On Jul 13, 2007, at 9:22 PM, Craig Johnson wrote:

> OK..I'm having a mental block.
>
>
>
> I have a website started with Ruby on Rails.
>
> I've got this object Hierarchy in mind.
>
>
>
> the simple "it's a database" stuff is fine.but when it comes to
> the Arrays
> of Hashes that make
>
> up some of the objects within the custom class.the relationship
> to the
> database and what happens when
>
> I close down the environment (and in future want to start up site.)
>
>
>
> So how do I Save and retrieve that stuff? do I have to do the
> Object/Relational mapping myself or
>
> do I depend on the "serialize" function/method for the class?
>
>
>
> the examples I've seen don't have a user create and populate a complex
> object and then
>
> save and retrieve it...things that are saved and retrieved seem pretty
> simple---though there
>
> are lots of instantiations and work live---but I need to create a
> datastore
> that gets extended and
>
> hit with queries---Am I going to have to recreate and repopulate via
> "deserialize" ?
>
>
>
> I imagine the answer is obvious---but it eludes my feeble mind..
>
> Help?
>
>
>
> cj:-)
>
Rails is BIG. Take it slowly. I'm still struggling with it too.
There are some good books on it. Work through them. It takes time for
the details to start sinking in.
Don't rush yourself. Rails comes with the stigma of fast development,
but the part about learning curve is often lost in the hype.
I'm frustrated with it myself, but the reality is, a framework takes
time to learn AND it pays off in the end because it's better than
building all of that functionality yourself.
in the meantime, check out streamlined...

John Joyce

4 Answers

Craig Johnson

7/14/2007 3:04:00 AM

0

John, appreciate your shot at it...

But---(and I don't' want to be a "Joe" here...) if anyone
has build a site/ruby app which creates and manipulates
complex object classes (things that have Arrays, or Hashes within
their Class definitions)...
How did you store those things in the database...

for example ... if I have a recipe which has Steps
which have ingredients tied to those steps I might want to
create an array of Steps, each of which can have both Actions and
an array of ingredients...
But...once a user has put in the receipe...and I've populated all those
objects within the instance....
I want to save it...
How?

throw me some ideas...
I'm thinking that I have to serialize the class...and that is what's needed.

cj:)

-----Original Message-----
From: John Joyce [mailto:dangerwillrobinsondanger@gmail.com]
Sent: Friday, July 13, 2007 8:45 PM
To: ruby-talk ML
Subject: Re: Web Databases and Objects


On Jul 13, 2007, at 9:22 PM, Craig Johnson wrote:

> OK..I'm having a mental block.
> I have a website started with Ruby on Rails.
> I've got this object Hierarchy in mind.
> the simple "it's a database" stuff is fine.but when it comes to
> the Arrays
> of Hashes that make
> up some of the objects within the custom class.the relationship
> to the
> database and what happens when
> I close down the environment (and in future want to start up site.)
> So how do I Save and retrieve that stuff? do I have to do the
> Object/Relational mapping myself or
>
> do I depend on the "serialize" function/method for the class?
> the examples I've seen don't have a user create and populate a complex
> object and then
>
> save and retrieve it...things that are saved and retrieved seem pretty
> simple---though there
>
> are lots of instantiations and work live---but I need to create a
> datastore
> that gets extended and
>
> hit with queries---Am I going to have to recreate and repopulate via
> "deserialize" ?
> I imagine the answer is obvious---but it eludes my feeble mind..
>
> Help?
> cj:-)
>
Rails is BIG. Take it slowly. I'm still struggling with it too.
There are some good books on it. Work through them. It takes time for
the details to start sinking in.
Don't rush yourself. Rails comes with the stigma of fast development,
but the part about learning curve is often lost in the hype.
I'm frustrated with it myself, but the reality is, a framework takes
time to learn AND it pays off in the end because it's better than
building all of that functionality yourself.
in the meantime, check out streamlined...

John Joyce


Todd Benson

7/14/2007 3:20:00 AM

0

On 7/13/07, Craig Johnson <cjsiam@msn.com> wrote:
> John, appreciate your shot at it...
>
> But---(and I don't' want to be a "Joe" here...) if anyone
> has build a site/ruby app which creates and manipulates
> complex object classes (things that have Arrays, or Hashes within
> their Class definitions)...
> How did you store those things in the database...
>
> for example ... if I have a recipe which has Steps
> which have ingredients tied to those steps I might want to
> create an array of Steps, each of which can have both Actions and
> an array of ingredients...
> But...once a user has put in the receipe...and I've populated all those
> objects within the instance....
> I want to save it...
> How?
>
> throw me some ideas...
> I'm thinking that I have to serialize the class...and that is what's needed.

Do you have a relational model already designed?

Like, for example, with recipes, you might have

create table recipes (
id int,
name varchar,
primary key id
);

create table steps (
id int,
number int,
recipe_id int,
ingredient_id int,
primary key id
);

create table ingredients (
id int,
name varchar,
primary key id
);

Note, that's just a hack-up. A real model would be more complex, and
would warrant constraints. But anyway, in Rails, these tables would
become classes that can become instantiated upon querying the
database.

Now, if you really just want to serialize data, then you wouldn't
really need a relational database at all. You would, however, lose
the power of the database for queries and data integrity.

hth a little,
Todd

John Joyce

7/14/2007 10:55:00 AM

0


On Jul 13, 2007, at 10:04 PM, Craig Johnson wrote:

> John, appreciate your shot at it...
>
> But---(and I don't' want to be a "Joe" here...) if anyone
> has build a site/ruby app which creates and manipulates
> complex object classes (things that have Arrays, or Hashes within
> their Class definitions)...
> How did you store those things in the database...
>
> for example ... if I have a recipe which has Steps
> which have ingredients tied to those steps I might want to
> create an array of Steps, each of which can have both Actions and
> an array of ingredients...
> But...once a user has put in the receipe...and I've populated all
> those
> objects within the instance....
> I want to save it...
> How?
>
> throw me some ideas...
> I'm thinking that I have to serialize the class...and that is
> what's needed.
>
> cj:)
>
> -----Original Message-----
> From: John Joyce [mailto:dangerwillrobinsondanger@gmail.com]
> Sent: Friday, July 13, 2007 8:45 PM
> To: ruby-talk ML
> Subject: Re: Web Databases and Objects
>
>
> On Jul 13, 2007, at 9:22 PM, Craig Johnson wrote:
>
>> OK..I'm having a mental block.
>> I have a website started with Ruby on Rails.
>> I've got this object Hierarchy in mind.
>> the simple "it's a database" stuff is fine.but when it comes to
>> the Arrays
>> of Hashes that make
>> up some of the objects within the custom class.the relationship
>> to the
>> database and what happens when
>> I close down the environment (and in future want to start up site.)
>> So how do I Save and retrieve that stuff? do I have to do the
>> Object/Relational mapping myself or
>>
>> do I depend on the "serialize" function/method for the class?
>> the examples I've seen don't have a user create and populate a
>> complex
>> object and then
>>
>> save and retrieve it...things that are saved and retrieved seem
>> pretty
>> simple---though there
>>
>> are lots of instantiations and work live---but I need to create a
>> datastore
>> that gets extended and
>>
>> hit with queries---Am I going to have to recreate and repopulate via
>> "deserialize" ?
>> I imagine the answer is obvious---but it eludes my feeble mind..
>>
>> Help?
>> cj:-)
>>
>
After creating your database schema, usually using script/generate
migration migration_name,

If you run the old
ruby script/generate scaffold
You'll be faced with a simple CRUD application.
It includes the pretty standard Rails naming of methods in the
controllers, it's in all of the tutorials online and elsewhere.
It is a bit cryptic as there isn't an explicit 'save by clicking
here' or anything,
but basically, the controllers talk to active record and do SQL for you.
SQL doesn't really do a 'save' as such, it saves as soon as the
record is created, the two are one and the same.
If you follow the conventions of Rails (I'm still learning them
myself, there is a lot to keep in your head)
naming conventions and what not, things should be saved and available
the next time.
The only thing to really shut down is the database and the server.
If the controllers, models, views and database are set up correctly,
your data should be saved.

I'm going to recommend the Sitepoint book Build Your Own Ruby On
Rails Applications, I just bought it today... based on a
recommendation or two that gave it high marks for going into details
like this. I'm also trying to get details like this, but different.
I'll be reading it tomorrow and if I find something clearer, I'll let
you know.

You could also try the Rails list but I've found it's not too
beginner friendly sometimes. It's pretty geared (like many of the
books) toward people that have built web apps in other languages before.



Craig Johnson

7/14/2007 3:25:00 PM

0

Thanks.
This be useful...
I figured it was a "duh" moment coming....

Will try it out....
thanks again....

-----Original Message-----
From: John Joyce [mailto:dangerwillrobinsondanger@gmail.com]
Sent: Saturday, July 14, 2007 4:55 AM
To: ruby-talk ML
Subject: Re: Web Databases and Objects


On Jul 13, 2007, at 10:04 PM, Craig Johnson wrote:

> John, appreciate your shot at it...
>
> But---(and I don't' want to be a "Joe" here...) if anyone
> has build a site/ruby app which creates and manipulates
> complex object classes (things that have Arrays, or Hashes within
> their Class definitions)...
> How did you store those things in the database...
>
> for example ... if I have a recipe which has Steps
> which have ingredients tied to those steps I might want to
> create an array of Steps, each of which can have both Actions and
> an array of ingredients...
> But...once a user has put in the receipe...and I've populated all
> those
> objects within the instance....
> I want to save it...
> How?
>
> throw me some ideas...
> I'm thinking that I have to serialize the class...and that is
> what's needed.
>
> cj:)
>
> -----Original Message-----
> From: John Joyce [mailto:dangerwillrobinsondanger@gmail.com]
> Sent: Friday, July 13, 2007 8:45 PM
> To: ruby-talk ML
> Subject: Re: Web Databases and Objects
>
>
> On Jul 13, 2007, at 9:22 PM, Craig Johnson wrote:
>
>> OK..I'm having a mental block.
>> I have a website started with Ruby on Rails.
>> I've got this object Hierarchy in mind.
>> the simple "it's a database" stuff is fine.but when it comes to
>> the Arrays
>> of Hashes that make
>> up some of the objects within the custom class.the relationship
>> to the
>> database and what happens when
>> I close down the environment (and in future want to start up site.)
>> So how do I Save and retrieve that stuff? do I have to do the
>> Object/Relational mapping myself or
>>
>> do I depend on the "serialize" function/method for the class?
>> the examples I've seen don't have a user create and populate a
>> complex
>> object and then
>>
>> save and retrieve it...things that are saved and retrieved seem
>> pretty
>> simple---though there
>>
>> are lots of instantiations and work live---but I need to create a
>> datastore
>> that gets extended and
>>
>> hit with queries---Am I going to have to recreate and repopulate via
>> "deserialize" ?
>> I imagine the answer is obvious---but it eludes my feeble mind..
>>
>> Help?
>> cj:-)
>>
>
After creating your database schema, usually using script/generate
migration migration_name,

If you run the old
ruby script/generate scaffold
You'll be faced with a simple CRUD application.
It includes the pretty standard Rails naming of methods in the
controllers, it's in all of the tutorials online and elsewhere.
It is a bit cryptic as there isn't an explicit 'save by clicking
here' or anything,
but basically, the controllers talk to active record and do SQL for you.
SQL doesn't really do a 'save' as such, it saves as soon as the
record is created, the two are one and the same.
If you follow the conventions of Rails (I'm still learning them
myself, there is a lot to keep in your head)
naming conventions and what not, things should be saved and available
the next time.
The only thing to really shut down is the database and the server.
If the controllers, models, views and database are set up correctly,
your data should be saved.

I'm going to recommend the Sitepoint book Build Your Own Ruby On
Rails Applications, I just bought it today... based on a
recommendation or two that gave it high marks for going into details
like this. I'm also trying to get details like this, but different.
I'll be reading it tomorrow and if I find something clearer, I'll let
you know.

You could also try the Rails list but I've found it's not too
beginner friendly sometimes. It's pretty geared (like many of the
books) toward people that have built web apps in other languages before.