Not sure how to call this, so the title might look a bit weird, but here is a short rails console example:
$ parent = Theme.first.pages.create(name: "parent")
=> #<Page id: 1, name: "parent", position: 1, ancestry: nil, ancestry_depth: 0, theme_id: 19>
Page Load (0.4ms) SELECT "pages".* FROM "pages" WHERE "pages"."ancestry" = '1' ORDER BY position ASC
$ child = parent.children.create(name: "child")
=> #<Page id: 2, name: "child", position: 1, ancestry: "1", ancestry_depth: 1, theme_id: nil>
Theme Load (0.5ms) SELECT "themes".* FROM "themes" WHERE "themes"."id" IS NULL LIMIT 1
I expected theme_id to be set the same as the parent. Is there something I am missing here? Or am I supposed to always do parent.children.create(name: "child", theme: parent.theme)?
parent.children.create(name: "child", theme: parent.theme)
I don't think it's logical that ancestry should take care of things like that; it is only meant to maintain a hierarchy. In your case, I'd add a before_create filter in Page to set the theme_id to the parent's theme_id (if any).
I see your point, and I guess a before_create filter would easily do the job. I was somehow expecting it to work like theme.pages.create works, where the new page takes the theme_id of the referenced theme due to the associations made in Rails.
Anyway, thanks for the reply.