Sriram Venkatesh
Sriram Venkatesh

Reputation: 593

Generating Models based of other models ruby on rails

So I have a model of Items with the following fields:

Highscore should have the following fields:

-Username (name) -Points (int)

I want to create a model of highscores that will iterate the Item model and find entiers that have the boolean being true. Then add the seeker to the highscore table with a point. If the user already exists then, just add an extra point to his entry.

How would I go about designing this type of database...

Upvotes: 0

Views: 57

Answers (1)

kiddorails
kiddorails

Reputation: 13014

I will never suggest iterating approach here. This is database we are talking about, and linear iteration over the data is unrealistic.

What you can do is use Observer. Read about them here - http://api.rubyonrails.org/classes/ActiveRecord/Observer.html

With this, you can check at the save and update callbacks and depending upon your boolean value, you can create/update the HighScore record.

Upvotes: 2

Related Questions