New on the blog: Associations Deep-Dive — hasMany,...
# wheels-dev
p
New on the blog: Associations Deep-Dive — hasMany, belongsTo, Nested Properties, and Eager Loading. <https://blog.wheels.dev/posts/associations-deep-dive-wheels-4/ > What it covers: • The three association types (belongsTo / hasMany / hasOne), how Wheels deduces modelName + foreignKey + joinKey from one
name
arg, and when to override them • The exact dynamic methods each one generates —
author.posts()
,
author.postCount()
,
author.addPost()
,
author.deleteAllPosts()
, and the rest — with a table per type •
dependent=
and its five legal values (delete / deleteAll / remove / removeAll / false). There is NO `nullify`; FK-nulling is
remove
/
removeAll
.
belongsTo
has no
dependent
at all. •
nestedProperties
— save a parent and its children from one form submit;
autoSave
defaults true,
allowDelete
defaults false • Eager loading with
include=
to kill the N+1, why nested
include="artist(genre)"
is query-only, has-many-through via
shortcut
, and why a polymorphic belongsTo can't be eager-loaded Plus a Sharp Edges section: getters return QUERIES not arrays, join-type defaults differ by association (belongsTo inner-joins and silently drops parentless rows), and mixed positional+named args error every time.
🙌 1