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 4538820
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:51:45+00:00 2026-05-21T14:51:45+00:00

I am not sure if what I want to do is wrong or just

  • 0

I am not sure if what I want to do is wrong or just my implementation.

what I want to do is

have multiple “has 1” relationships between a person and addresses

my models are

class Person
  include DataMapper::Resource

  property id,serial
  property name,String

  has 1, :home, :model => 'Address'
  has 1, :office, :model => 'Address'
  has 1, :mail, :model => 'Address'
end

class Address
 include DataMapper::Resource
 property :id,Serial 
 property addr1, String
 property country, String
end

This works fine in code and I can assign and access country of a person

a_person.home.country

but when I save then retireve from DB it does not work. It mixes up home, office and mail addresses

I was hoping to get a structure like

CREATE TABLE `addresses` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `addr1` varchar(50) DEFAULT NULL,
  `country` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
)

CREATE TABLE `persons` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  'home' int(10) unsigned ,
  'office' int(10) unsigned ,
  'mail' int(10) unsigned ,
  PRIMARY KEY (`id`)
) 

what I got was

CREATE TABLE `addresses` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `addr1` varchar(50) DEFAULT NULL,
  `country` varchar(50) DEFAULT NULL,
  `person_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `index_addresses_person` (`person`)
)

CREATE TABLE `persons` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
)

the table structure is not important to me, what I want is that home,office and mail are all the same object type and perferrably are in the same table. It would be nice to be able assign the same Address instance to say, both home and mail and have it stored only once in addresses but referenced twice.

P.S. people and addresses are not the actual underlying object they are just used as a familiar example.

Edit: I may be able to do what I want by putting 4 has n assoc on Address. I will try and edit my answer with the results.

  • 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-05-21T14:51:46+00:00Added an answer on May 21, 2026 at 2:51 pm

    Actually you might want something like this:

    class Person
      include DataMapper::Resource
    
      property :id, Serial
      property :name, String
    
      belongs_to :home,   :model => Address
      belongs_to :office, :model => Address, :required => false
      belongs_to :mail,   :model => Address, :required => false
    end
    
    class Address
      include DataMapper::Resource
    
      property :id,Serial 
      property :address, String
      property :country, String
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure what I'm doing wrong here, I just want to be able to
I'm not sure what's wrong here, all i want to do is randomly grab
Not sure if I am being totally wrong here but I want to do
Never used fwrite(), so I'm not sure exactly what I'm doing wrong. I'm just
I'm new to Django, and I'm not sure what I want is possible: I
Not sure if this is possible. I want to grab the latest X stories
Im not sure that its possible to do what I want to accomplish. I
Not sure if you can do this, but I want to select the first
Not sure if I can do it this way. I want to get current
I'm not sure how to approach this: I want a TreeView that will display

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.