similar to: saving a has_one association question

Displaying 20 results from an estimated 10000 matches similar to: "saving a has_one association question"

2009 May 25
4
after_create and has_one association bug?
Hello, I''ve come across an issue that I''m sure is a bug when using after_create with a has_one association, but I''m not 100% certain if I''m missing something. This is pretty much exactly the code I''m using. Two simple classes (Account and Contact) and I create the contact after I create an account (via after_create). I''m not passing in a
2013 Mar 05
4
searching model and has_one association
Howdy. I have these models: User, field "mundane_name" user has_one :instructor_profile (may or may not exist) instructor_profile, field "sca_name" belongs_to :user I would like to craft a search on these fields, which is effectively this, but in one go: matching_users = User.where("mundane_name ILIKE ?", "%#{target}%") matching_profiles =
2006 Feb 17
3
Using :include with has_one vs. has_many
While I''m happy to continue talking about the vagaries of Rails deployments, I also need to actually build apps. :) I may have discovered a bit of a problem with :include as it applies to has_one associations. First, let me say that I''m a big fan of :include for reducing the number of SQL calls. There are times when I wish it could go more than 1 step away from the parent
2006 May 12
1
can I fake has_one :through?
I''m having a difficult time wrapping my head around a set of models and their associations and seeing how they map into Rails. I''ll try to lay out my problem using the has_many and belongs_to structures. I have a RuleSpace, a Rule, and a Subject. A RuleSpace has_many Rules A RulesSpace has_many Subjects through Rules A Rule belongs_to (many) RuleSpaces A Rule has_many
2008 Sep 29
1
has_one :through with :source. How to alias association?
Hi to everyone, I have the following models: class Attachment < ActiveRecord::Base has_attachment :content_type => [:image, ''application/pdf''], :max_size => 3.megabytes, :path_prefix => ''../private/attachments'', :storage => :file_system, :processor => :rmagick,
2007 Oct 18
4
Polymorphic Association?
Hi there- I''m a newbie to this board, RoR, and web development in general. So please forgive me if this is in the wrong place or if the solution is really simple... I''m trying to conceptualize the relationships between a series of models for a page creation function. What I''d like is to have a Content Page which consists of a series of Content Blocks. The Content
2006 Mar 14
4
has_one
I''ve got an order model that stores order data. One piece of data is a credit card type, which is a digit 1,2 or 3. I have a cardType model that has an id, shortName and LongName for the credit card merchant (visa, mastercard, amex). I want to be able to say: order.cardType.shortName, but can''t seem to get has_one working. It works with has_many and a finder_sql statement on
2006 Apr 07
2
has_one not using the pk?
Hello, im trying to wrap a fairly ugly legacy schema using AR. How to handle normalized informations which aren''t connected via the pk? create table what ( myid int, myclass int, ;; references blahclass.blahid mygender int ) create table blahclass ( blahid int, mdesc1 text, fdesc1 text) ) I would like to wrap this as class What < AR::Base has_one :blahclass class
2010 Oct 07
1
Question on polymorphic association
I have 3 models . Doctor, Patient and User with following associations class Doctor < ActiveRecord::Base has_many :patients, :dependent => :destroy has_one :user, :as => :userable accepts_nested_attributes_for :user end class Patient < ActiveRecord::Base belongs_to :doctor has_one :user, :as => :userable accepts_nested_attributes_for :user end class User <
2010 May 11
1
has_one/belongs_to -- accessing the subordinate
With a has_one/belongs_to relationship, what''s the best way to guarantee that the belongs_to object gets created and is accessible alongside the has_one object? I *think* the after_create callback is a good choice, but I discovered an oddity while trying it. F''rinstance, if every horse has a carriage: ============ ActiveRecord::Schema.define do create_table(:horses) {|t|
2006 May 16
1
:conditions on has_one realationship
Hi there, I''m currently building a membership application and I want to be able to select, not just all the memberships, but the most current membership from the database on a per user basis. I have linked the tables as shown:- class Membership < ActiveRecord::Base belongs_to :payment belongs_to :person end class Person < ActiveRecord::Base has_many :memberships
2006 Jun 14
5
InstantRails Lost connection to MySQL server
Hiall, I just tried out InstantRails version 1.3a. After a virgin install and filling the fresh mysql db with my app schema, I tried runningthe app with webrick, only to see the infamous "Lost connection to mysql server" for every action. What is it that I''m doing wrong? I also have mysql 5 installed on my machine, but the service is stopped while experimenting with
2008 Apr 29
4
Default values for belongs_to and has_one
There really doesn''t seem to be a *declarative* way to define a default value for belongs_to and has_one associations class Person < ActiveRecord::Base belongs_to :address end p = Person.new p.address.city = ''Atlantis'' # Bummer! Of course, there''s an easy way to avoid this class Person < ActiveRecord::Base belongs_to :address
2006 Feb 20
1
belongs_to, has_one, has_many question (again?)
Hi All, Probably this has been asked numerous times, I apologize already! Can somebody point me to a good tutorial on how Rails works with relations? I know about database design and normalization, I also know about programming in general (and OOP for that matter). Only thing I can say is that I''m following the "Four days on Rails" tutorial by John McCreesh. He writes
2006 Apr 17
2
has_one problem in a form
Hello all, I have a syntax question. How does one refer to a field brought in via a has_one/belongs_to relationship in a form helper? Basically, I have two models: class Resource < ActiveRecord::Base has_one :other_thing end class OtherThing < ActiveRecord::Base belongs_to :resource end It has the normal id-resource_id foreign key relationship. OtherThing has two fields, plus the
2012 Aug 17
3
Rails doesn't validate create_model or build_model (has_one association)
I''ve got User has_one Shop. Rails is not validating when I tried create_shop or build_shop, neither in the browser nor the rails console. My code: class Shop < ActiveRecord::Base attr_protected :user_id belongs_to :user validates_presence_of :name, :primary_address, :city, :country_code, :currency end class ShopsController < ApplicationController before_filter
2007 Aug 21
4
[AWDwR] Confused about has_one and has_many
Heya everyone! I am quite new to Rails and I am reading AWDwR. I am at Task E "Check Out!". I understand it quite well, but I have a problem with the last playground exercise: Add a Table which contains the payment types. All goes well, but I am not sure whether I should use has_many or has_one(as in the Playground wiki at http://wiki.pragprog.com/cgi-bin/wiki.cgi/PT-E-3). I use the
2006 May 18
6
Form actions with additional parameters
Hiall, I want to give the action of a form an additional parameters but can''t figure out how to do it. My code looks like this <%= start_form_tag :action => ''create'', next_step => true %> <%= render :partial => ''user_form'' %> <%= render :partial => ''community_form'' %> <%= submit_tag
2006 Apr 02
7
RANT: belongs_to -> refers_to
Every once in a while, I pipe up and whine that "belongs_to" should really be ''refers_to" [http://dev.rubyonrails.org/ticket/2130]. It''s time again. I''ve got a bunch of stuff going onto eBay, so, like any good engineer, I don''t just post it manually: I design a Rails-based inventory database that creates a semantically-correct XHTML/CSS auction
2006 Apr 15
1
Is this a HAS_ONE bug?
Let''s say I have: A BELONGS_TO B B HAS_ONE A (with :dependent=>:nullify) But this association does not need to exist. In other words, I could have many A''s and B''s that are not associated in this manner. Presently, if I try to delete "B": 1. If B is associated to an "A", this works fine and A.my_B is nullified. 2. If B is NOT associated, I