Skip to content

Strategy to handle nested records #1386

Answered by groue
tgrapperon asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @tgrapperon,

I don't doubt that the A type is the one you want your app to use. It's the "canonical" model. My advice is to not make it use unfit protocols.

A can implement FetchableRecord (please refer to its documentation, as well as the Associations guide).

But A is not a "table record", because TableRecord is all about single tables. For example, when TableRecord generates SQL for A.fetchAll(db), it does not embed the Bs.

And A is not a "persistable record" either. If you think about it, persisting a composite object such as A supports multiple strategies. For example, what deleting an A should do? Maybe your app wants to delete rows in both the A and B tables. Maybe some other …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tgrapperon
Comment options

Answer selected by tgrapperon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants