Questions tagged [has-one]
385 questions
0
votes
1 answer
Why my simple ExtJS data example with associations does not work?
from my point of view I build the simplest way of model with associations in ExtJS.
Model:
Post --hasOne--> User
What I did:
Using a memory proxy
Follow the rule: Proxy in Model
Load a post object by Post.load(...).
But when I try to get the user…

Fred
- 1
- 2
0
votes
2 answers
Polymorphic association fails
In my rails 3.2 application I have a User model and a Physician model with the following polymorphic associations:
User
class User < ActiveRecord::Base
attr_accessible :authenticatable_id, :authenticatable_type, :email
belongs_to…

Dennis Hackethal
- 13,662
- 12
- 66
- 115
0
votes
1 answer
rails 3 has_one radio button
Having problems creating radio buttons in a form using has_one
Model
Class User
has_one :role
accepts_nested_attributes_for :role
Class Role
attr_accessible :name
belongs_to :user
Controller
@user = build_role
Form for radio buttons

jmorrissette
- 31
- 5
0
votes
2 answers
rails has one association problems
I have models Productor, Company and User
I want that a productor AND a company have both an user. An user that belongs to a Company belongs only to this company. An user that belongs to a Productor belongs only to this productor.
so the tables I…

thiagoh
- 7,098
- 8
- 51
- 77
0
votes
2 answers
Rails: How can this be done with a has_one association?
My model has two columns, one named foo_id and the other bar_id.
I'm wondering if it's possible to turn these two simple methods into has_one associations:
class SomeModel < ActiveRecord::Base
def foobar_foo
Foobar.find( self.foo_id )
end
…

Marco
- 4,345
- 6
- 43
- 77
0
votes
1 answer
Polymorphic has_one association and multiple inheritance with Rails 3
I've seen some posts dealing with this, and am trying to determine the best solution.
Semantically, I want a Client model with a one-to-one relationship with a Survey. There are different kinds of surveys that have different fields but I want to…

user206481
- 248
- 5
- 13
0
votes
1 answer
has_one association and nested form
I have a model Post:
class Post < ActiveRecord::Base
has_one :draft, class_name: Post, foreign_key: draft_id
end
In routes.rb I have the following:
namespace :admin do
resources :posts do
resource :draft
end
end
What I want to achieve is…

oldhomemovie
- 14,621
- 13
- 64
- 99
0
votes
1 answer
How do I modify my form partial to handle a has_one association?
This is the relevant part of my _form.html.erb
<%= form_for(@score) do |f| %>
<% if @score.errors.any? %>
<%= pluralize(@score.errors.count, "error") %> prohibited this score from being saved:
…
marcamillion
- 32,933
- 55
- 189
- 380
0
votes
2 answers
has_one, belongs_to What am I doing wrong?
I have Users and each user sets a Goal. So a goal belongs_to a user and a user has_one: goal. I am trying to use form_for in the view to allow the user to set their goal up.
I figured it would be like microposts (which is straight from Hartl's…

Steve Q
- 395
- 5
- 28
0
votes
1 answer
Rails has_one relationship safe resource.build_resource in controller
I have a page that takes a user through a short sign up tutorial when they create their account in order to create their first resource. In my app, :hotel belongs to :user, and :user has_one hotel. For the tutorial page, in my controller, I have:
…

Tim Reistetter
- 829
- 1
- 12
- 17
0
votes
1 answer
Rails3 FactoryGirl has_one unknown attribute error
I have the following setup:
Models:
class Product < ActiveRecord::Base
has_one :product_category
attr_accessible :name, :product_category, :product_category_id
end
class ProductCategory < ActiveRecord::Base
belongs_to :product
…

Bryce
- 2,802
- 1
- 21
- 46
0
votes
1 answer
Extjs sync hasOne model on store sync
I have two models: first one is PersonAddress, which contains info about person and address and second one is Address, which contains info about some address.
I connect this to models with PersonAddress hasOne Address. Now I have store…

Luft-on
- 179
- 1
- 13
0
votes
1 answer
Rails : Set form inputs with a has_one relation
In my rails app, I have a relation between User table (which is dedicated to authentication purpose) and Store table (which contains store information, like the name, description,...).
I mapped the two models like this:
User has_one :store
Store…

Hassen
- 6,966
- 13
- 45
- 65
0
votes
2 answers
Rails 3 has_one / belongs_to relationship with model in subdirectory
I'm trying to create a simple relationship but with a model in a subdirectory under Rails 3.2
I have a User class and each user has an email subscription.. Because There will be other types of subscriptions (which also fill be added to users) I put…

hershey
- 465
- 1
- 8
- 19
0
votes
1 answer
Rails Saving Models in Wrong Order
i've been searching around for some time now and can't seem to figure out what is causing this, I had a model working saving a volunteer and his home and work addresses. I changed something (cant seem to figure out what for the life of me) and now…

Ken Koch
- 426
- 3
- 12