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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:36:22+00:00 2026-06-03T09:36:22+00:00

The specific instance I am referring to is here. I want to use a

  • 0

The specific instance I am referring to is here. I want to use a row from the Grid table to be the value of the Grid property in the Driver table. But I cannot get updates in the Grid table to persist through to the Grid property on the Driver table
I want to use a row from the Race table to be the value of the Race property in the Driver table.

Here is the code for the datamapper stuff.

require "rubygems"
require "json"
require "sinatra"
require "sinatra/reloader"
require "sqlite3"
require "data_mapper"

DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/season.db")


class Driver
    include DataMapper::Resource
    property :id, String, :key => true
    property :ptd, Integer
    property :races, Integer
    property :grid, Object
    property :race, Object
    property :hcScore, Integer
    property :domScore, Integer
end

class Grid
    include DataMapper::Resource
    property :id, String, :key => true
    property :AUS_Q, Integer
    property :MAL_Q, Integer
    property :CHI_Q, Integer
    property :BAH_Q, Integer
end

class Race
    include DataMapper::Resource
    property :id, String, :key => true
    property :AUS_R, Integer
    property :MAL_R, Integer
    property :CHI_R, Integer
    property :BAH_R, Integer
end

class Team

    include DataMapper::Resource
    property :id, String, :key =>  true
    property :domScore, Integer
    property :drivers, Object
end

DataMapper.finalize.auto_migrate!

In irb I will do something like

irb(main):001:0> require "./season.rb"
=> true
irb(main):002:0> v = Driver.create id: "VET"
=> #<Driver @id="VET" @ptd=nil @races=nil @grid=nil @race=nil @hcScore=nil @domScore=nil>
irb(main):003:0> g = Grid.create id: "VET"
=> #<Grid @id="VET" @AUS_Q=nil @MAL_Q=nil @CHI_Q=nil @BAH_Q=nil>
irb(main):004:0> v.grid = Grid.get "VET"
=> #<Grid @id="VET" @AUS_Q=nil @MAL_Q=nil @CHI_Q=nil @BAH_Q=nil>
irb(main):005:0> v.save
=> true
irb(main):006:0> g.update(:AUS_Q => 6)
=> true
irb(main):007:0> v
=> #<Driver @id="VET" @ptd=nil @races=nil @grid=#<Grid @id="VET" @AUS_Q=nil @MAL_Q=nil @CHI_Q=nil @BAH_Q=nil> @race=nil @hcScore=nil @domScore=nil>
irb(main):008:0> Grid.get "VET"
=> #<Grid @id="VET" @AUS_Q=6 @MAL_Q=nil @CHI_Q=nil @BAH_Q=nil>
irb(main):009:0> AUS_Q = 6 in the Grid table but in the Driver table it continues to be nil!

As you can see – AUS_Q in the Driver table continues to be nil even though I set it to be 6 in the Grid table.

Chances are I am doing it wrong and there is an easier way to do this. I encourage all corrections and smackdowns.

  • 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-03T09:36:23+00:00Added an answer on June 3, 2026 at 9:36 am

    I would suggest that you use belongs_to to create association between resources, and that you use an identity map, like this:

    require "sqlite3"
    require "data_mapper"
    
    class Driver
        include DataMapper::Resource
        property :id, String, :key => true
        belongs_to :grid, :required => false
    end
    
    class Grid
        include DataMapper::Resource
        property :id, String, :key => true
        property :AUS_Q, Integer
    end
    
    DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/season.db")
    DataMapper.finalize.auto_migrate!
    
    DataMapper.repository(:default) do
      v = Driver.create id: "VET"
      g = Grid.create id: "VET"
      v.grid = Grid.get "VET"
      v.save
      g.update(:AUS_Q => 6)
      puts v.grid.AUS_Q
      puts Grid.get("VET").AUS_Q
    end
    

    Everything you do within the block initiated by DataMapper.repository(:default) do will use an identity map. Thus, identical objects in the database will result in identical objects in memory.

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

Sidebar

Related Questions

Specific instance of Problem I have an int range from 1-100. I want to
One specific instance, I want to set a BP on every switch(msg) handled in
How to tell if instance specific Salesforce URL is from Sandbox or Production, if
How to select all records,that may contain specific value that is known, without referring
I'm wondering, and hoping, if I can access and use a specific instance of
Is the widget id that you receive from the OS for a specific instance
I want to register a specific instance of an object for a type in
I have a textReader that in a specific instance I want to be able
I need to get a specific instance of a running object (from c#). It
In upgrading from ExtJS3 to ExtJS4, one specific instance of our prior code not

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.