07-20-2023, 01:42 PM
I'm creating a model with a db table for my image uploads because each image is going to have multiple versions and is also going to have alt text, description, an optional caption, and a photo credit that needs to be carried with it.
My blog posts are going to have one or more of these images. I can select the table row for the image, chose the size, apply the CSS, and then cause that to generate in the body of my post. Fabulous! I don't think it makes any sense to have a has_many association here--I just want some arbitrary set of images to render in the body of the post. It's all content, not structure.
BUT one image will be special. Each blog post will have exactly one featured image. This is the image that will be used with the post on other pages, in previews, when it's linked to using twitter or facebook, etc. So I BELIEVE that I should have a has_one association from blog post to image, and a has_many (will probably have one, but just in case) from image to blog post.
I am COMPLETELY new to databases and a new to Rails, too. I just want a sanity check on this.
Thanks so much!!!!
My blog posts are going to have one or more of these images. I can select the table row for the image, chose the size, apply the CSS, and then cause that to generate in the body of my post. Fabulous! I don't think it makes any sense to have a has_many association here--I just want some arbitrary set of images to render in the body of the post. It's all content, not structure.
BUT one image will be special. Each blog post will have exactly one featured image. This is the image that will be used with the post on other pages, in previews, when it's linked to using twitter or facebook, etc. So I BELIEVE that I should have a has_one association from blog post to image, and a has_many (will probably have one, but just in case) from image to blog post.
I am COMPLETELY new to databases and a new to Rails, too. I just want a sanity check on this.
Thanks so much!!!!