similar to: Problem destroying some record with relations has_many has_one

Displaying 20 results from an estimated 3000 matches similar to: "Problem destroying some record with relations has_many has_one"

2007 May 14
0
building and saving has_many and has_one relations
Hi, I am very confused about an aspect of has_one and has_many relations, with regard to using the build method, and saving the belongs_to side. It''s a somewhat long post. so please bear with me :) First let''s consider the has_one scenario. Let''s say I have a student who must own exactly one car: class Student has_one(:car) end class Car belongs_to(:student)
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
2007 Dec 06
0
has_many :through with a has_one source
Here is my simple example... require ''rubygems'' require ''active_record'' ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => "has_many_through.db" ActiveRecord::Schema.define do create_table "containers", :force => true do |t| t.column :name, :string end create_table "shapes",
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
2009 Jul 15
0
has_many and has_one ... and nested form
Hiya I am looking at Rails 2.3.2 and how to cleanly do the following: - I have model User - User has many Plans - User has one Active Plan - New User form has fields on it to create the Active Parent I want to create a new User with an Active Plan in one form. At the moment I have: class User < ActiveRecord::Base has_one :active_plan, :class_name => ''Plan'',
2007 Apr 21
0
has_many / has_one polymorphic with conditions
I''m looking for a way to make this work (I think the code is more explanatory at this point): ## THIS WORKS has_many :images, :as => :imageable, :dependent => :destroy, :order => ''position ASC'' # @product.images => # ## THIS DOESNT has_one :featured_image, :as => :imageable, :conditions => "position = 1" # @product.featured_image =>
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 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
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
2011 Mar 07
1
has_one :dependent => :destroy error (in `configure_dependency_for_has_one': compile error (SyntaxError))
Hi I''m getting the following error : /Users/nikosd/.rvm/rubies/ree-1.8.7-2011.02/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/nikosd/.rvm/gems/ree-1.8.7-2011.02@.../bin/rake test Testing started at 12:00 PM ... (in /Users/nikosd/Work/.../.../...)
2010 Oct 04
1
Splitting a DF into rows according to a column
Hi, I'm turning my wheels on this and keep coming around to the same wrong solution - please have a look and give a hand ... The premise is: a DF like so > loremIpsum <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque leo ipsum, ultricies scelerisque volutpat non, volutpat et nulla. Curabitur consequat ullamcorper tellus id imperdiet. Duis semper malesuada
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
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
2008 Feb 19
0
Issue with Observers and has_one association...
Hey Guys, I''m getting a peculiar bug working with Observers and has_one associations. When a has_one association is invoked by an Observer it always returns null. I looked in the development.log file and the SQL for the has_one association isn''t even being executed. On the other hand, when I replace the has_one association with just a hand crafted method, it does get called
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,
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
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
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
2012 Nov 19
0
has_one :through NoMethodError: undefined method `klass' for nil:NilClass when doing class_name on reflection
Not sure if this is expected or not. Only happened with a has_one :through I had setup. (Workaround is just to remove it and go through the association manually vs has_one ..., through: .) Not a big deal if no one has time to look at it, as it''s not a big enough deal to look into a fix on our side. In Rails (3.2.9) console if I do: MyModel.reflections.each {|name,reflection|
2006 Nov 04
0
one to many relationship; has_one
I''m new to ruby and rails and as a result am a bit lost on implementing a one to many relationship. In my DB I have 2 tables contents and locations, contents contains the foreign key location_id. I generated a content and a location model using rails scripts and then edited the models as follows class Content < ActiveRecord::Base has_one :location end class Location <