Frederick Cheung wrote:
Sounds like you shouldn't be using update_all at all here, rather you
should be using find to find an appropriate row to update and if there
is none, create a new one.
Fred
Again, the problem is I don't know how. I'm simply guessing based on
what I see with the documentation. I don't have any working examples
and most of the tutorials I see are very basic..
How I plan to manage the data is important as well.
For instance, I want to keep weekly data snapshots. So, as an example
just using the rushing offense table:
A user will be able to check by a particular week (the cron job will run
the rake task once per week)
Therefore, my database table needs to account for "new data" every
single week.
Scenario:
Rake Task begins
Check for weekly snapshot data (for current week)
-- If no snapshot data then create it
-- If data already exists for current week do nothing
Next Week
Rake Task begins
Check for weekly snapshot data (for current week)
-- If no snapshot data then create it
-- If data already exists for current week do nothing
So, let's look at my current table structure:
:rank
:name
:games
:carries
:net
:avg
:tds
:ydspg
:wins
:losses
:ties
So, the first issue I see is that I do not have a column that accounts
for some type of weekly snapshot event notification. Would you
recommend this be tied to a timestamp? How would I check (based on the
conditions above) to check against a particular timestamp range and
produce the results..?
Or should I create another column to check this out?
And, lastly, is there somewhere online that code is available to view
for "advanced table manipulation"? Much of the code that I have found
is either very outdated, very basic, or not something I can use. The
documentation is a decent start but it does not contain a lot of
advanced examples..
I know I may be asking a lot of questions (and I apologize if I am).
However, I do learn quickly and I'm the type of person that likes to
dive in and get started. I've read one full ruby book and am midway
through my first rails book. However, even these books do not provide
me scenario based examples.
This is why I'm here. I am better at understanding code when I see
code. I don't mind working through code that contains errors and trying
to get it to work. That just helps me gain an understanding of what
occurs. The API can only be used as a code bits reference. I always
look there first but which code are you looking for? If you know
exactly what method you are going to be working with, looking in the API
and then scouring the web for information is a little easier. In the
case of my example above, I'm not sure which methods I will be working
with exactly to accomplish my task.
Thanks.