简体   繁体   中英

Generating Models based of other models ruby on rails

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

  • Name (string)
  • Description (text)
  • Hider (string)
  • Seeker (string)
  • Long (float)
  • Lat (float)
  • Keyword (string)
  • Found (boolean)

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...

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM