0

I have a model to keep track of points a student earns. Sometimes they earn 1 point and for some tasks they earn multiple points. The table would look something like this:

points
--------------
student_id:integer
task_id:integer
points:integer
earned_at:date

What should I call this model? Point or Points? Typically my models are singular and Rails intelligently pluralizes it in the appropriate places. But in this case each record represents a number of points. When I call student.points I want it to return all the points they've ever earned. When I call student.points.first I want it to return the first group of points they earned.

Using Rails 3.2.8

at.
  • 50,922
  • 104
  • 292
  • 461

1 Answers1

0

I'd keep the model singular; think each Point item as a "point record" or "point group" which contains multiple points. Also, I'd change the 'points' attribute to 'amount' or something, as Point.amount seems cleaner than Point.points.

Check out: https://stackoverflow.com/a/3399753/1700540 and I'm sure you can find other resources with similar opinions.

Community
  • 1
  • 1
JCoster22
  • 387
  • 5
  • 9
  • Bit more formal source: http://itsignals.cascadia.com.au/?p=7 Check out their reference to naming models. – JCoster22 Oct 01 '12 at 18:07
  • What you say makes sense and I definitely like the amount field vs points. But a table called Point just feels so awkward. I'll mull it over in my mind for a minute. – at. Oct 01 '12 at 18:12
  • I guess Rails will make the table called points if I name the model Point. Still the model being called Point feels so awkward. – at. Oct 01 '12 at 18:13
  • I work on a website where we use a model called Point, and, I agree, it does seem awkward to name a collection of multiple points a Point. If it helps with how it sounds, you could potentially call it something like PointRecord, Award, or Credit. I would have changed our name of the Point model, but the website is far too established to be making foundational changes like that. – JCoster22 Oct 01 '12 at 18:34
  • What would you call your Point model if you could change it @JCoster22? PointBundle, PointKit, PointBatch, PointPack, PointBunch, PointGroup, PointSet? What about PointCount? Then it makes sense to say something like `student.point_counts.each {|points| puts "#{points.amount} earned on #{points.earned_at}"}`. – at. Oct 02 '12 at 17:22
  • Yeah, PointCount, PointGroup, or PointRecord would be my top choices. And definitely good choice going with attribute 'amount' instead of 'points.' – JCoster22 Oct 03 '12 at 17:52
  • I ended up using PointsLog. Figured each entry was a log entry for the number of points earned for a particular task. If it was instead a table of the total points for each student, then I would call it Score. – at. Oct 03 '12 at 17:56