similar to: belongs_to question

Displaying 20 results from an estimated 9000 matches similar to: "belongs_to question"

2005 Dec 15
3
Another session question
I want to give a user a form to create a new Product, but instead of persisting the product to the database I want to store it in a session first for category assignment, etc.. (in other controllers) So when the user describes the product on the form I have a "Save and Continue" button pointing to the action add_to_product_factory: def new_product @product = get_product end
2006 Jan 12
2
Can A Model Have Many belongs_to?
I am very new to Rails. After skimming through the documentation over the last several days, I''m struggling with the appropriate use of belongs_to. My main question is whether a model can have several belongs_to declarations. I have not seen any examples online show that usage. If it can, then I would like to know if it''s poor form or what the best practices are around
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 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 Mar 23
3
when (not) to use belongs_to
I know you get a lot of questions like this, but I couldn''t find one which answers exactly what I''m after. I''m reasonably new to rails, and I''m having a bit of trouble with when to use belongs_to. On the rails wiki ( http://wiki.rubyonrails.org/rails/pages/belongs_to), it says "In general, the Foo model belongs_to :bar if the foo table has a bar_id foreign
2006 May 21
3
find with belongs_to -> belongs_to -> belongs_to
I have 3 tables keywords (keywords attached to a file) files (info about the file) paths (path for the file) [This is a legacy database, so I can''t change this] keyword belongs_to file and file belongs_to path. Users need to be able to search the keywords, but they only have access to certain volumes, so the results need to be limited by the path. I also need to show paging,
2006 Nov 09
2
redefining the method belongs_to in ActiveRecord::Base
Hi. I''ve tried to redefine the method belongs_to in ActiveRecord::Base, so every time a model is defined as belonging to :attachment, it should have some additional methods. I tried to do an alias of belongs_to, but this was not successful. The error message in Webrick was > Booting WEBrick... ./script/../config/../lib/ActiveRecordExtensions.rb:67: undefined method
2006 Apr 25
4
belongs_to :through
belongs_to :through Why is that not possible? We should have: Street belongs_to :city belongs_to :country, :through => :city -- Posted via http://www.ruby-forum.com/.
2006 Oct 30
2
It this possible: finder_sql-like behavior for belongs_to?
Guys, I have a need to support as has_many/belongs_to relationship on a legacy(kind of) schema. The reason I say kind of is that the schema does have "id" columns that are used in many associations, but this particular has_many/belongs_to association needs to support different ones. I''ve attached to code at the end of this email. Suffice it to say I need to use the standard
2006 Jul 11
1
counter_cache, has_many and belongs_to
I am a bit confused about counter_cache here. The API docs http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html say that only the belongs_to association can take the :counter_cache option. When I try to use it on a has_many I get an "unknown key(s): counter_cache" error. Why would this be the case? belongs_to means that this model has a field with an id
2006 Jun 29
4
Multiple belongs_to
Let''s say I have a catalog with hotels. Each hotel belongs to a category (4-star, 5-star etc.) This is it''s official category.However, there is also a category that users assign and a category that "independent reviewers" assign. So I have this: hotels { id, category_id, reviewer_category, user_category } categories { id, name } class Hotel <
2009 Jun 27
1
Problem with :touch in belongs_to
I''ve read in rails api that there is a touch parameter and I want to use it in my application. I have something like that class User < ActiveRecord::Base has_many :phones after_update :updated def updated ... end end class Phone < ActiveRecord::Base belongs_to :user, :touch => true end I want that every change of any phone number would change User updated_at
2006 Apr 18
1
habtm and belongs_to one table
I have the following: Posts belong to a User Posts may be Monitored by many Users How do you characterize this? class Post < ActiveRecord::Base belongs_to :user has_many :monitors class Monitor < ActiveRecord::Base has_many :posts, :as => user class User < ActiveRecord::Base has_many :posts # when a user *does* a post belongs_to :monitor, :polymorphic => true --
2006 Jun 23
0
adding action after a belongs_to assignment
What is the best way to add action after a belongs_to assignment? (Just like ''after_add'' in has_many assignment). I see that there is no callbacks for belongs_to. I have tried overriding parent= : alias :parent_before_mod= :parent= def parent=(the_parent) parent_before_mod = the_parent if save # my actions here end end but when I tried to assign parent, parent_id
2008 Jan 30
0
Plugin belongs_to Model Association Bug
Hey all, I''m not positive if this is a Engines bug, but it seems very peculiar and a few hours of Googling haven''t given me any good leads yet, so I thought I''d see if it makes sense to any of you: I am writing a new version of the savage_beast plugin (implements Beast forums as a plugin) that''s Rails 2.0 compatible, and I am having trouble with the many
2011 Jan 11
0
[PATCH] Polymorphic belongs_to association with :conditions issues
Hey all, Could use a few eyes on a couple of very simple patches at https://rails.lighthouseapp.com/projects/8994/tickets/6262 if any has some time. The issue (from the ticket description): If you define a polymorphic belongs_to association and it has conditions on it, those conditions cause a NameError when you try to access the target object, of the style saying "hey, there''s no
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 24
4
Problem having two belongs_to of the same class type
I have a Shipment class that is used to ship packages between Branches. However, when I try to have two belongs_to in Shipment called shipped_to and shipped_from I can''t seem to make it work. I can get it to display the form properly but when I select the branches and click save I get the following error... "Branch expected, got String" Any ideas? I have added some code
2006 Feb 06
1
belongs_to versus references
I was just reading through the Rails book and I got to the part about belongs_to versus references. Shouldn''t references be allowed as a synonym to belongs_to? Looking at this from a schema in the model view point, belongs to corresponds to a foreign key with the cascade on delete option. References is just a normal forgeign key with no cascade option. -- Jon Smirl jonsmirl@gmail.com
2010 Jun 10
1
RSpec 2: uninitialized constant - mocking belongs_to AR relation
gems/ruby-1.9.2-head/bundler/gems/rspec- core-2398fcadf5beb256bed9c548c59445d3b4c8a047-master/lib/rspec/core/ backward_compatibility.rb:26:in `const_missing'': uninitialized constant Message::User (NameError) from /Users/kristianconsult/.rvm/gems/ruby-1.9.2-head/bundler/gems/ rspec-expectations-996c752171a0a0e16347e934dadc25767e31186c-master/lib/