Questions tagged [has-one]

385 questions
0
votes
1 answer

linking to table and returning value

i am trying to query a table and return a value if the conditions are met. schedule model class Schedule < ActiveRecord::Base belongs_to :result attr_accessible :result_id end results model class Result < ActiveRecord::Base has_one…
Boss Nass
  • 3,384
  • 9
  • 48
  • 90
0
votes
2 answers

Grails hasOne and hasMany same domain

I have domain like this: class Team { hasOne [leader: Person] hasMany [member: Person] } class Person { belongsTo [team: Team] } But when the tables are generated, there is not a column like leader_id in the team table. And thus the leader…
Shaoxuan
  • 33
  • 4
0
votes
1 answer

Saving result of has_one association to avoid fetching DB in Rails?

I have a has_one association between User model and Player model. I see myself doing current_user.player so many times in controllers and views, and I feel like I am hitting the DB way too much every time I do that. Also it would be nice to have a…
Hommer Smith
  • 26,772
  • 56
  • 167
  • 296
0
votes
4 answers

Rails Active Record Associations

I've been reading and re-reading the Rails associations guide: http://guides.rubyonrails.org/association_basics.html This were close but not quite the same: Ruby on rails active record associations I'm not sure how to setup the following…
Zhao Li
  • 4,936
  • 8
  • 33
  • 51
0
votes
1 answer

Activerecord relation creation via has_one

I Rails if you have a model Walrus that has_many :bubbles (and Bubble belongs_to :walrus, you can create a new Bubble that is associated with the Walrus like so: chuckles = Walrus.create chuckles.bubbles.create But what if Walrus has_one :bubble?…
Chris
  • 11,819
  • 19
  • 91
  • 145
0
votes
1 answer

has_one with :class_name, and belongs_to relation not setting attributes correctly in rails 3.2.3

I'm trying to make a form to set values to two children objects through has_one (with :class_name option) and belongs_to relation. However, when I input and submit values through the form, both children objects have the same value even if I input…
Ryo
  • 2,003
  • 4
  • 27
  • 42
0
votes
1 answer

Model to belong to several attribute in another model

This might be a silly question but I'm slightly confuse here : I have a user model, which has 2 attributes : hair and eyes, that can have a color value. Instead of referencing the color as a string twice in the hair and eye column of the user…
cl3m
  • 2,791
  • 19
  • 21
-1
votes
2 answers

Edit data b/w two models in cakephp

I have two models, one is Login and the other is Userdetail. I saved data from model Login in both models using the hasone relationship. Please let me know how it would be possible to edit them. I used the following code for save in my add.ctp…
Mehak
  • 11
  • 4
-1
votes
2 answers

CakePHP: hasOne relationship returns null for fields

I have 2 models, Venue and Contact, where 1 venue has 1 contact, but 1 contact can be responsible for many venues. In my tables, venue.contactid references the column contact.id My models look like this: class Contact extends AppModel { public…
Jonno_FTW
  • 8,601
  • 7
  • 58
  • 90
-2
votes
1 answer

Rails has_one belongs_to display field in index?

I have two models : season and category. I want to display the category name in the season index view. class Season < ActiveRecord::Base attr_accessible :nb_down, :nb_up, :name, :category_id has_one :category accepts_nested_attributes_for…
John
  • 198
  • 2
  • 10
1 2 3
25
26