Is there a simply way to check if two models are associated?

Hey guys,

I spent last night trawling through the rails API looking for some sort of @object1.associated_with?(@object2) and couldn't find anything, but it seems so fundamental.. Does anything like this exist?

if not, i might build a simple plugin/gem to mimic this behaviour.

Mark

Mark Y g wrote:

Hey guys,

I spent last night trawling through the rails API looking for some sort of @object1.associated_with?(@object2) and couldn't find anything, but it seems so fundamental.. Does anything like this exist?

Sure. Assuming you have your associations set up properly (for example, User has_many :posts), you could do @post.user == @user or @user.posts.include? @post.

if not, i might build a simple plugin/gem to mimic this behaviour.

Mark

Best,