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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:20:47+00:00 2026-05-25T18:20:47+00:00

So I’m having some trouble with DataMapper and object associations. (Code provided at bottom).

  • 0

So I’m having some trouble with DataMapper and object associations. (Code provided at bottom). I’m getting errors upon saving to the extent that some id’s are not set, which I think has something to do with how I setup my associations/not fully understanding how associations work under DataMapper.

The code I’m running is:

Rose.setup_datamapper
Rose::User.first_or_create(:username => 'some-user', :password => 'REDACTED')

Rose::User.all.each do |user|
   user.scrape_and_update
   user.errors.each { |e| puts e } unless user.save
   user.bandwidth_entries.each { |e| puts e }
end

And the errors I am recieving are:

 ~ (0.000064) SELECT "id", "username", "password" FROM "rose_users" WHERE ("username" = 'some-user' AND "password" = 'REDACTED') ORDER BY "id" LIMIT 1
 ~ (0.000042) SELECT "id", "username", "password" FROM "rose_users" ORDER BY "id"
 ~ rose_bandwidth_entries.device_network_address may not be NULL (code: 19, sql state: , query: INSERT INTO "rose_bandwidth_entries" ("policy_mbytes_received", "policy_mbytes_sent", "actual_mbytes_received", "actual_mbytes_sent", "timestamp", "bandwidth_class", "user_id") VALUES (583.34, 39.58, 590.27, 44.26,  '2011-09-20T13:39:31-04:00', 0.0, 1), uri: sqlite3:/Users/axiixc/Dropbox/Ruby/stats.sqlite?port=&adapter=sqlite3&fragment=&path=/Users/axiixc/Dropbox/Ruby/stats.sqlite&scheme=sqlite3&host=&user=&password=&query=)

Model classes are here: http://www.pastie.org/private/xer5grfaulmnxalne6g5va (link for brevity)

EDIT Okay the crash is coming from create on line 26:

# /Library/Ruby/Gems/1.8/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:114:in `execute_non_query': rose_bandwidth_entries.device_network_address may not be NULL (DataObjects::IntegrityError)

main_entry = BandwidthMainEntry.create(
    :user => self,
    :timestamp => Time.new,
    :policy_mbytes_received => scrape_dict[:main][:policy_mbytes_received],
    :policy_mbytes_sent => scrape_dict[:main][:policy_mbytes_sent],
    :actual_mbytes_received => scrape_dict[:main][:actual_mbytes_received],
    :actual_mbytes_sent => scrape_dict[:main][:actual_mbytes_sent],
    :bandwidth_class => scrape_dict[:main][:bandwidth_class]
 )

So would it have something to do with the inheritance from BandwidthEntry/BandwidthDeviceEntry, because that class doesn’t even have an association with a device.

Might as well post the full stack trace too: http://www.pastie.org/private/ospnkeeylul9mhf4fgxhdq

EDIT Okay, here is basically the rest of the code http://www.pastie.org/private/pwmihpa6vu3h7lypx64ag

I can never tell how much to post, sorry!

  • 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-25T18:20:47+00:00Added an answer on May 25, 2026 at 6:20 pm

    Okay, so I derped on inheritance, and should have read more of the documentation. What was happening was I missed the property :type, Discriminator needed when using subclasses. So even though my one subclass didn’t need a device associated with it, the other did, so that’s what was triggering the error.

    My working model looks like this: http://www.pastie.org/2564668

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
i got an object with contents of html markup in it, for example: string
I have some data like this: 1 2 3 4 5 9 2 6

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.