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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:34:36+00:00 2026-06-14T04:34:36+00:00

I got a main table and a bezirk table. When i insert data into

  • 0

I got a main table and a bezirk table.

When i insert data into my main table, i want to insert data in my bezirk table as well. And the entry i am creating in bezirk, should have the id of the main table.

Main Model:

class Main < ActiveRecord::Base
   attr_accessible :category, :latlon
   has_one :bezirk
   accepts_nested_attributes_for :bezirk
end

Bezirk Model:

class Bezirk < ActiveRecord::Base
  attr_accessible :beznr, :coordinates, :district_code, :id, :name
  belongs_to :main
end

And here is how i tried to do it…

    main = Main.new(:category => "Bezirk", :latlon => 'POINT(1,2)')
    main.save
    bezirk = main.bezirks.new(:name => 'test', :beznr => 2, :district_code => 1160, :coordinates => 'POINT(1,2)')
    bezirk.save

So… how am i able to insert into bezirk, the corresponding main id!? so that i have an association between two entries…

  • 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-14T04:34:37+00:00Added an answer on June 14, 2026 at 4:34 am

    You can use this:

    # create main
    main = Main.create(:category => "Bezirk", :latlon => 'POINT(1,2)')
    
    # create bezirk belongs to main, so bezirk will have main_id, is id of main
    bezirk = main.create_bezirk(:name => 'test', :beznr => 2, :district_code => 1160, :coordinates => 'POINT(1,2)')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So basically I have been trying to insert columns into my third table from
I'm trying to insert data into a table in a database, but the insertion
I've got m2m relationship like this: #main table CREATE TABLE products_product ( id integer
I've got main folder: c:\test And there I have 2 folders: Movies and Photos.
Can't understand what is a problem here: I have got main.cpp file where I
In Unix, I have got three main files. One of them is a library
I got 2 tables storing prices of the product. The main table is Product
I'm using the Linq to Entities. I've got my main table, Employee setup with
Got table for main product listing: | id | name | content | 1
I've got a table with the following structure table#Main tbody tr.Row td input.EditRow My

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.