Relationships Revisited

Ok…so I posted yesterday regarding relationships between:

Users
Products
Purchases

Thanks all for the answers; very informative. What I’m really running
up against is more an issue like Dave T. describes wrt
articles/users/reads in ADWR. So, using that as the OM:

Articles
Users
Reads

Dave uses the has_and_belongs_to_many idiom to join Users and Articles
via Reads without ever promoting “Reads” to a proper model. My
questions is: is this still the current train of thought in the rails
community (meaning just using habtm).

Dave does suggest that the users_articles table is just a mask for
what should be a model, so assuming that I do promote Reads to a
model…let’s talk relationships:

  • A User has many reads
  • A Read belongs to a user
  • An Article technically doesn’t belong to anything
  • Does a Read have an explicit relationship to an Article? What is that
    relationship? Why am I confounded re: something that seems so trivial.

Arrrgh! Help!

Hi Cory, Read does have an explicit relationship to an Article as you
can
see in the model. Please see the code snippet below:

class Article < ActiveRecord::Base
has_many :readings
end

class User < ActiveRecord::Base
has_many :readings
end

class Reading < ActiveRecord::Base
belongs_to :article
belongs_to :user
end

What are you trying to accomplish within your project?

-Conrad

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs