similar to: Question about Associations

Displaying 20 results from an estimated 10000 matches similar to: "Question about Associations"

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
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 Mar 20
11
has_many brings back ''uninitialized constant''
hello. first things first - I am new to ruby on rails (ruby, too), so I''m figuring this is just a basic newbie error. I''m creating a basic photography website. And I have two tables with a relationship: photos: - id (set up as PK) - title - shutter - aperture - date - the_order ...etc photo_comments: - id (set up as a PK) - photos_id (set up as a FK) - author - date -
2006 Feb 10
15
"Ruby for Rails" in early access release
Hi -- My book "Ruby for Rails" is now being released one chapter at a time through the Manning Early Access Program, with the whole book due to appear on May 1. If you''re interested, see http://www.manning.com/books/black (I guess I could have just sent my sig with no body, but anyway :-) David -- David A. Black (dblack@wobblini.net) Ruby Power and Light
2006 Jul 17
14
REST Relationship Models
I''m trying to figure out an elegant way to do this: I have the following three tables: people, employer, employees And consequently the following three models: class Person < ActiveRecord::Base end class Employer < ActiveRecord::Base has_many :employees end class Employee < ActiveRecord::Base belongs_to :person belongs_to :employer end I want to be able to say:
2006 Jul 07
3
Newbie Model question (HABTM?)
All, If I have a table that has several discrete fields that all point to the same associated field, how do I model it. Specifically, If I have a project table that has 2 fields: specifying_company, and responsible_company. And one table of associated companies, how do I do the :belongs_to / :has_many stuff ie. For a given project company A may be writing the spec, but company B may be paying
2006 Feb 10
12
Accessing ''many'' variables
Hi, I have a class called Outlet which has_many Jacks. Apart from internal id, each jack is unique by the attribute ''color''. I''d like to iterate through each Outlet, and be able to output data for a Jack of a certain color. Say, I want to access the orange jack for the current outlet: <td><%=h outlet.jack.color[''O''].ip_address
2006 Jun 03
8
confused about ActiveRecord relationships
I am very confused about where to put the belongs_to and the has_one (and other relationship identifiers). I have read the RDoc and the agile book many times about this and I think i still see it backwards. Let me outline my app so you have an understanding... I have 2 tables: Schools { id, school_name, address_id } and Addresses { street1, street2, city, state, zip, country } *** this
2006 Apr 27
5
ERb on he command line re: Ruby For Rails book
Hi, I am working thru the Ruby for rails book. On page 30 David Black talks about running erb from the command line i.e. $ erb erbdemo.rb just as you would a normal ruby prog ($ ruby erbdemo.rb) but when I try to do this I get command not found. How do I make this work? I am running Linux (Ubuntu Breezy) Regards, Paul
2006 Mar 24
7
Polymorphic associations?
I''ve read the stuff about polymorphic associations here: http://wiki.rubyonrails.org/rails/pages/UnderstandingPolymorphicAssociations But I''m not sure what exactly they are and what their advantage is. Are they the same as HABTM, but they''re "two-way"? Joe -- Posted via http://www.ruby-forum.com/.
2005 Dec 15
8
How to ensure deletes cascade to associated models?
I have the following models: class Resume belongs_to :resume_assignments end class User belongs_to :resume_assignments end class ResumeAssignment has_one :resume has_one :user end When I delete a resume, I want to make sure that its associated ResumeAssignment gets deleted also. Calling destroy_all to delete some resumes doesn''t seem to do this. Is there an option that will
2007 Dec 02
3
Better way for select list for belongs_to?
I''m currently doing all of this just to have a drop-down list of Courses for a particular student: ===== edit template ===== <%= f.select :course, @courses, :selected => @student.course.id %> =================== ===== students controller ===== def edit @student = Student.find(params[:id]) @page_title = "Edit #{@student.full_name}" @courses =
2006 May 11
7
[ANN/ADV] Ruby for Rails now published in paper!
Hi -- I''m on the road, so I haven''t laid eyes on it yet -- but word on the virtual street is that "Ruby for Rails: Ruby techniques for Rails developers" is now out in paper. It will probably take a little longer to trickle to your neighborhood Barnes and Noble... but you can order it now from the publisher. See http://www.manning.com/black. And trickle it will, too.
2010 Apr 15
12
[PATCH] Add :touch option to has_many associations
Hi, it would be nice to have the touch option in has_many associations also. I have a scenario like this: An user has some credit (money) and some advertises. Each advertise can be enabled or disabled depending on some rules. One of the rules is that the user should have money. Each time the money of the user change, the advertises are touched, enabled/disabled and then cached, as they are much
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 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 Jul 11
7
Rails associations: Easy Question requires dumb answer
***Scroll down to see the dumb quick question*** I have two Models: class Template < ActiveRecord::Base end which has this migration: /snip t.column :name, :string And the other model: class Product < ActiveRecord::Base has_one :template end with the migration: /snip t.column :qty, :integer, :default => 0 t.column :specialDescription, :string t.column
2006 May 31
7
How to render from with <%%> ?
I have a loop that I iterate through in my view. <% coll.each do |itm| puts(itm.value) end %> How do I render the itm.value without using a <%= %> tag? Should puts not work? Joerg P.S. There is a good enough reason for me wanting to do this :-) -- Posted via http://www.ruby-forum.com/.
2007 Sep 05
8
Hi..Guys new plugin again
Hi.. Guys new plugin again Foreign Key Associations is a plugin that automatically creates associations based on foreign-keys. The associations are created at runtime-ie. as your ActiveRecord models are loaded-so they will always be up-to-date. For example, given a foreign-key from a customer_id column in an orders table to an id column in a customers table, the plugin creates:
2006 Mar 23
4
belongs_to more than one model
Suppose I have one table: states id statename And I have two other tables that contains states: houses id color state_id places id place_name state_id How would my model relationships look like? class State < ActiveRecord::Base belongs_to house belongs_to place end class House < ActiveRecord::Base has_one state end class Place <