similar to: can I fake has_one :through?

Displaying 20 results from an estimated 3000 matches similar to: "can I fake has_one :through?"

2008 Sep 16
3
has_one :through eager-loading problem
I have a problem with the :include option in find for my has_one :through association. I have Users, Profiles and Customers, all connected to each other with a has_one :through => :membership association like this: class Profile < ActiveRecord::Base #could also be user or customer has_one :membership # i saw an acrticle of Ryan about has_one :through, there this would be has_many, is
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,
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
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 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 Sep 27
5
Question about has_one
I have a question about regarding the use of ''has_one'' in this scenario: Schema: User ---- id first_name last_name UserMessage ---- user_id message_id Message ---- id Assuming business rules dictate that a Message can have at most ONE User (let''s assume a message can be created without a user associated to it), these are my questions: 1) How would I use has_one
2006 Jun 21
1
ActiveRecord has_one default value
My apologies if this is a dumb question, but I''ve searched around and haven''t been able to come up with a solution. Is there a way when specifying a has_one association to specify a default value for an object if data is missing in the child table. For instance: class Student has_one :university end if no university is associated to the student in the database, I would
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 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 Jul 17
2
Trouble with has_one
Hi, I''m trying to write a blog application where each post has a single header image associated. My models: ---------- class Post < ActiveRecord::Base belongs_to :blog has_many :images has_one :header end class Header < ActiveRecord::Base file_column :image_path end class Image < ActiveRecord::Base belongs_to :post file_column :image_path end The controller targets I
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
2010 Nov 28
6
has_one accepts_nested_attributes_for fields_for NOT WORKING HELP
MODEL class User < ActiveRecord::Base has_one :address, :dependent => :destroy accepts_nested_attributes_for :address end CONTROL def new @user = User.new @user.build_address # Adicionei ... VIEW partial _form .... <% f.fields_for :address do |b| %> # Adicionei <%= b.text_field :city_manual %> # Adicionei <% end %>
2006 Jan 18
2
categories/recipes & books/descriptions - has_many vs has_one => id question
People, In the cookbook eg, categories has_many recipes but in a book eg, book has_one description - doesn''t that mean that the id of the description should be the same as the id of the book (instead of having it''s own "description_id" in the book table? Thanks, Phil. -- Philip Rhoades Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275) GPO Box 3411 Sydney
2006 Jan 31
4
has_one without inverse belongs_to
I have two models called entity and user. The entities table has a column called users_id that contains the user id of the user that created the entity. In entity I have... has_one :user ... as I want to be able to show the user who created the entity from the entity object. But this produces the following error... Mysql::Error: #42S22Unknown column ''users.entity_id'' in
2006 Mar 03
6
has_one :next - invalid name?
I have this in a model: has_one :next, :class_name=>''WorkPart'', :foreign_key=>''next_id'' And it causes this error: compile error /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/deprecated_associations.rb:83: void value expression
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 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
2010 Oct 04
2
newbie q on activerecord - has_one and has_many on same table?
Hi I have a table where I need to identify one of the children as the "prime" child. So, its like: Parent has_many :Child has_one: Child :as :prime_child (?) or something like that? Do I put something like prime_child_id in the Parent table? Thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this
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
2005 Sep 19
1
help with has_one relationship??
Hi I''m new to Rails and I''m struggling with a ''has-one'' relationship. I''m trying to save product and image data in seperate tables with one to one relationship. I''m assuming the problem lies in the controller method below but can''t work it out. The models contain the has_one and belongs to statements, and I tried swapping these