Top "Associations" questions

Associations typically refer to relationships between models in ORMs such as ActiveRecord.

Rails Associations - has_many => :through - but same model

What I am trying to do: I have a blog and want to show related posts below the main post. …

ruby-on-rails associations has-many-through
Rails association for two foreign keys for the same table in one table

I am new to RoR and still playing with associations. I need to have two references to a particular model …

ruby-on-rails associations
Rails: How to limit number of items in has_many association (from Parent)

I would like to limit the number of items in an association. I want to ensure the User doesn't have …

ruby-on-rails activerecord callback associations
Rails has_one vs belongs_to semantics

I have a model representing a Content item that contains some images. The number of images are fixed as these …

ruby-on-rails model associations
Rails - Custom html into simple_form label

I'm trying to customize the output of a simple_form association, basically I need to display a checkbox label on …

ruby-on-rails associations simple-form
has_many through association dependent destroy under condition of who called destroy

Is there a way to check, within a before_destroy hook, what object (class) called destroy? In the following example, …

ruby-on-rails associations destroy
When to use association, aggregation, composition and inheritance?

I've seen plenty of posts on Stackoverflow explaining the difference between the relationships: associations, aggregation, composition and inheritance, with examples. …

python inheritance associations aggregation composition
Rails has_many through aliasing with source and source_type for multiple types

So here is a sample class class Company < ActiveRecord::Base has_many :investments has_many :vc_firms, through: :investments, …

ruby-on-rails activerecord associations has-many-through has-many
how to preselect an association checkbox using simple_form

I have this piece of code, while using simple_form: = simple_form_for :report do |f| = f.association :presets, :collection =&…

ruby-on-rails checkbox associations simple-form
Rails idiom to avoid duplicates in has_many :through

I have a standard many-to-many relationship between users and roles in my Rails app: class User < ActiveRecord::Base has_…

ruby-on-rails activerecord associations idioms