Top "Has-many" questions

has_many indicates a master-detail relationship.

how to avoid duplicates in a has_many :through relationship?

How can I achieve the following? I have two models (blogs and readers) and a JOIN table that will allow …

ruby-on-rails ruby duplicates has-many-through has-many
Undefined property: Illuminate\Database\Eloquent\Relations\BelongsTo::$name laravel 5.4

Hi following are my relations User Model public function loginlogout() { $this->HasMany("App\Models\LoginLogoutLogs"); } and this is my …

php laravel-5.4 has-many belongs-to
Rails - check if record exists in has_many association

I'm not sure if my question is worded correctly. I have three models: User, Item, and UserItem. user has_many :…

ruby-on-rails activerecord associations has-many
Rails has_many association count child rows

What is the "rails way" to efficiently grab all rows of a parent table along with a count of the …

ruby-on-rails grouping has-many
Rails: belongs_to vs has_one

A bit of a newbie question on rails associations. I have a Bug model, and a Status model. Status is …

ruby-on-rails model associations has-many belongs-to
Multiple hasMany relationships to same domain class in Grails

I'm using Grails, and I have a domain model with multiple hasMany attributes to the same domain class, which looks …

grails gorm has-many
How it works - `belongs_to :user, dependent: :destroy`

I know how to work has_many :posts, dependent: :destroy. If User or something that has_many posts is destroyed, …

ruby-on-rails ruby has-many belongs-to
Rails: Non id foreign key lookup ActiveRecord

I want ActiveRecord to lookup by a non-id column from a table. Hope this is clear when I give you …

ruby-on-rails activerecord foreign-key-relationship has-many belongs-to
Is it possible to create a conditional association in model?

I have setup a role based access controll system with the following models: Role (as STI), UserRole (global roles) ProjectRole (…

ruby-on-rails conditional has-many polymorphic-associations single-table-inheritance
Rails form with nested attributes (accepts_nested_attributes_for)

I have this one to many relationship: class Programa < ActiveRecord::Base attr_accessible :descripcion, :nombre, :roles_attributes has_many :…

ruby-on-rails nested-attributes has-many