Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation for use with associations #84

Open
SirRawlins opened this issue Jan 31, 2019 · 5 comments
Open

Improve documentation for use with associations #84

SirRawlins opened this issue Jan 31, 2019 · 5 comments

Comments

@SirRawlins
Copy link

Great gem folks 👍

However, I'm struggling a little to see how to work this with draft associations, and I think it's something which could perhaps be covered in the documentation?

Let's say I have a draftable blog post, and a post can have various tags associated with it.

class Post < ApplicationRecord
    has_drafts
    has_many :tags
end

class Tag < ApplicationRecord
    belongs_to :post
end

Drafting changes to the blog post in isolation is simple enough, I can change it's title, or correct some typos in it's content, that's working just lovely.

However, what if I want to change the tags associated with my blog post?. How can I make those association changes 'draft' rather than immediate?

How would model/controller code look in a scenario like that?

If someone can help me understand, I'm happy to wrap up a PR to improve the README around this.

@jmfederico
Copy link
Collaborator

You mean edit a tag and make that tag a draft? If that that is the case, you should make Tag draftable:

class Post < ApplicationRecord
    has_drafts
    has_many :tags
end

class Tag < ApplicationRecord
    has_drafts
    belongs_to :post
end

You can then draft and publish Tags.

If that is not the case, please clarify.

@SirRawlins
Copy link
Author

@jmfederico thanks for the suggestion, that makes sense.

Do the draft? and publish! methods cascade? i.e. if I publish a post, will it publish all it's draft tags? Or vice-versa, will publishing a draft tag also publish its parent post?

@jmfederico
Copy link
Collaborator

When you publish a child, and the parent is new (never published), the parent also gets published.

@jmfederico
Copy link
Collaborator

Publishing the parent does not publish the child.

@SirRawlins
Copy link
Author

@jmfederico 👍 thanks, that makes a great deal of sense.

Let's imagine I have a many-to-many association (has_many :through), such as, tags -> taggings -> posts. Where tags already existing, but I want to 'draft' the assignment of them to any given blog post.

I presume I would add draftsman to the join model? And then I can draft and publish the links, and perhaps cleanup before publishing to remove previously published associations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants