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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:01:27+00:00 2026-05-21T05:01:27+00:00

Hi im quite beginner in rails. i have a problem suggestion will be appreciated.

  • 0

Hi im quite beginner in rails. i have a problem suggestion will be appreciated.
i have two model “user” and “asset”
an “asset” is created by a “user” and asset” can be assigned to a “user” schema is

Asset { id,name,creator_id,assigned_to_id,price,...}

User{ id,name,....}

now in Asset model class association are

class Asset < ActiveRecord::Base
{
 #validation
belongs_to :creator ,:class_name=>'User'
belongs_to :assigned_to, :class_name=>'User' ,:foreign_key=>'assigned_to_id'
}

and User Model is

class User < ActiveRecord::Base
{
#any validation and other stuff
has_many :assets #did not specify either this association  is for creator , or   assigned_to  user.how can is specify that??
}

now in Asset show view i can obtain creator name with

@asset.creator.name

but can’t assigned_to name

@asset.assigned_to.name =>(error is )undefined method `first_name' for nil:NilClas

and
@asset.assigned_to_id.name=>(error is) undefined method `first_name’ for 1:Fixnum

any suggestion how can i make double association with same model

  • 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-21T05:01:28+00:00Added an answer on May 21, 2026 at 5:01 am

    ok solution was in my last comment.
    Multiple relation with same model

    class Asset < ActiveRecord::Base
    
    belongs_to :creator ,:class_name=>'User'
    belongs_to :assigned_to, :class_name=>'User' 
    
    end
    

    user.rb

    class User < ActiveRecord::Base
    
    has_many :created_assets, :foreign_key => 'creator_id', :class_name => 'Asset'
    has_many :assigned_assets , :foreign_key => 'assigned_to_id', :class_name => 'Asset'
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite a beginner at database design. I have two problems that I'd like
I'm a beginner jquery user so I'm really hoping this will be quite straight
I am a beginner to ruby on rails.But i am quite comfortable with php,
I'm a beginner at Andengine, but I have read quite a lot of tutorials
I'm quite new to threading in Python and have a couple of beginner questions.
I'm a beginner at Ruby on Rails so I apologize if this is quite
Python beginner here. I've looked around and found similar questions but can't quite cobble
I am an extreme beginner and have done quite a bit of searching on
I am a definite beginner to iPhone programming. I have two simple questions. 1)
I am a beginner user of linux, and also quite newbie at ssh and

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.