Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8755371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:50:36+00:00 2026-06-13T13:50:36+00:00

I got a model called Pages that looks like this: title description image_id background_image

  • 0

I got a model called Pages that looks like this:

title
description
image_id
background_image
logo

I also got a model calles Images that looks like this:

id
title

What I would like to be able to is to associate these three fields with the image model.

image_id
background_image
logo

image_id works perfectly because of the Page model association:

has_many :images

How do I make it work with background_image and logo?
Hope my question makes any sense. Thanks

UPDATE
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:50:37+00:00Added an answer on June 13, 2026 at 1:50 pm

    In your Page model, you’ll want to use belongs_to to specify that it contains a pointer to an Image. For the first one, that’ll just be belongs_to :image.

    But you want to have three pointers. You can do that; for each of the other fields, you’ll add an option to belongs_to to specify that it’s pointing to an Image. You do that using the :class_name option, like this;

    belongs_to :logo, :class_name => 'Image'
    

    You’ll also probably want to name your columns with _id at the end, so background_image_id and logo_id – it’s more Railsy that way.

    All of this is documented in the Rails Guides; the :class_name option is specifically here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a model like this: matrices ( matricesID integer; x integer; y integer;
I've got a model like this def upload_location(instance, filename): return 'validate/%s/builds/%s' % (get_current_user(), filename)
I've got a model, and my instance called show_user_image : class user_image(models.Model): title =
I've got a model called ImplicitTest . It's called this as having a Ruby
I've got an app that deals with websites. There's a model called sites, which
I've got a model in CakePHP that doesn't have a table, called Upload. I've
Ive got the following problem. I have a model called user which has a
I've got model that use ExtendAssociations , but for some reason deleteHABTM doesn't seem
I've got a model that has a nested property, which has more nested properties.
I'm using CodeIgniter and I got a model that fetches let's say all recipes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.