similar to: Basic Relationship Problem

Displaying 20 results from an estimated 8000 matches similar to: "Basic Relationship Problem"

2006 Mar 19
2
Multiple polymorphic belongs_to declarations
I have the following models: class Card < ActiveRecord::Base belongs_to :deck belongs_to :front, :polymorphic => true belongs_to :back, :polymorphic => true end class TextContent < ActiveRecord::Base has_one :card, :as => :front has_one :card, :as => :back end The conflicting has_one declarations don''t work. What I need is
2006 Oct 13
3
Validation errors in has_one/belongs_to relationships.
I have two objects, QuoteInput and Insured. QuoteInput has one Insured and Insured belongs to QuoteInput. I don''t understand what I''m seeing. I assign an Insured to a QuoteInput. The Insured object has invalid data. I call save! on the quote input. QuoteInput has no validations. I expect two things to happen - 1) an exception should be thrown, indicating that there was a
2006 Apr 28
2
file_column with polymorphic table relationship?
Hello, I''m just starting out with both Rails and Ruby, so I hope this isn''t too simple of a question - but I''ve been struggling to find a solution. I''m using the file_column plugin to handle image uploads and thumbnail generation. In addition, I''ve wrapped the image into a polymorphic table so I can have uploaded images associated with multiple
2010 May 25
2
Site Navigation With Polymorphic Has Many Through
Hi, seem to keep running into a wall here. I can''t find any resources on site navigation that can deal with any model being in the nav, allow nesting, and can dynamically update. So I thought about it for a while, and decided on a MenuItems class, which contained the position of the child in relation to it''s siblings, where the parent and the child were polymorphic. Then a given
2006 Jul 27
25
Why are has_one objects resaved when the parent is saved?
If the associated object of a has_one association has been loaded, it is resaved when the parent is saved. Eg: class Person < ActiveRecord::Base has_one :user end class User < ActiveRecord::Base belongs_to :person end p = Person.find(:first) p.save # As expected, nothing happens with the user association p.user # Loads the associated object p.save # As well as saving the person, the
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
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 Jun 06
1
Please Help with single table inheritance relationships
I''ve been searching the web, wikis, and more, and I haven''t turned up examples of how to have multiple entities in a single-table inheritance related to anything. I have an addresses table, but multiple entities can have Addresses: both Person (which has 2 addresses) and Retailer. I''ve been told that I need to use single-table inheritance, and this was my attempt:
2007 Oct 15
2
Association Help , 2 Teams playing a FootballGame
So I have the models class FootballGame < ActiveRecord::Base end and class Team < ActiveRecord::Base end I want to be able to do something like this @t1 = Team.create(:name=>"Michigan Wolverines football") @t1.save @t2 = Team.create(:name=>"Penn State Nittany Lions football") @t2.save @g = FootballGame.create(:hometeam => @t1, :awayteam => @t2) @g.save
2006 Jul 30
3
ActiveRecord - Multiple Address for a single record
I''m trying to figure out the Rails way to model the following problem: I have 2 tables. One (let''s call it location) contains a single address. The other (let''s call it company) contains 3 address. I''m trying to figure out the best way to model this. I''ve created an address table, a set up the model as follows: class Address <
2006 Apr 09
4
Inheritance via Though Associations?
I posted something about this a week ago wihtout response, but have made some progress since. However, I''m still not getting exactly what I want. OK, three core tables: create_table :reference_items do |t| t.column :title, :string, :limit => 255 t.column :year, :integer, :limit => 4 t.column :type, :string t.column
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 04
8
inherits_from: Multiple table inheritance
Hey guys, I just implemented very simple and primitive class table inheritance in ActiveRecord. The goal is for this to become mature enough to become a true feature in Rails. Check it out here: http://guest@blog.raylucke.com/svn/inherits_from Here?s how it looks in action: create_table "books", :force => true do |t| t.column "product_id", :integer t.column
2006 Jan 10
8
Noob: Child records not saved
Hi all, happily coding along, but it seems a belongs_to record is not saved. # Create some stuff def create_project @contact = Contact.new @project = Project.new(@params[''project'']) @project_contact = ProjectContact.new(@params[''collect'']) @project.project_contact = @project_contact contact =
2006 Aug 17
6
what did I do to my app? (Superclass mismatch?)
It was working before (as far as I can tell), but I freezed_edge and now... The first time I load this page, it works fine, the second time I get the superclass mismatch, the third time (and any subsequent times ) i get undefined method. I think this means my class is getting loaded twice? my model looks like this: class Quotation < ActiveRecord::Base has_many :price_breaks has_many
2007 May 22
3
Comments wanted about spec''ing out a couple controller methods
(oops, accidentally sent this to the rspec-devel list, sorry about that) Could someone help me spec out these Rails controller methods? I don''t know where to get started, especially with the transaction stuff. Or, if anyone else could suggest ways I could improve the code, that would be great as well. Puzzle has_one Media. Both are AR model objects. class PuzzlesController <
2008 Apr 18
3
has_many and belongs_to with non-primary foreign keys
Hi, I''m having a bit of trouble with my first Rails app. ---- I have two tables: create_table :items do |t| t.column :created_at, :timestamp t.column :user_id, :int t.column :text, :text end create_table :users do |t| t.column :user_id, :int t.column :name, :string end ---- I''m trying to use the "user_id" field to link both tables, with each user
2008 Apr 07
2
Simple active record issue. I must be missing something.
Here''s a seemingly simple ActiveRecord use case. I have Projects and Users. Each project has a single team leader as well as a review team that consists of several users. I would like to use the same User model for authentication and just reference these users in my Project model. I tried this but got an "unknown column" error (for User.project_id) class Project has_one
2005 Dec 29
1
Resolving ambiguous columns during a join
I am working with an existing schema and thus limited in how much I can bend my existing column names. I have a table Users, and a table ForumUsers, for which I have a "has_one" relationship - a user has_one forumuser. When I look at my user records I wish to include some information from forumuser: @users = User.find :all, :include => :forum_user, :order =>
2006 Aug 16
3
AR: column methods?
In a model, it seems that methods for column access are only created when one column method on an object is accessed. So, how can one override the default column methods? For instance: create_table "dogs", :force => true do |t| t.column "color", :string end create_table "tails", :force => true do |t| t.column "dog_id", :integer,