similar to: Updating a relationship in a has_many and belongs_to

Displaying 20 results from an estimated 9000 matches similar to: "Updating a relationship in a has_many and belongs_to"

2006 Aug 01
2
has_many :through a belongs_to relationship
I have users who belong to a group. I also have a room that belongs to a group. I want to use a has_many through association to link the room and the users as such: class Room < ActiveRecord::Base belongs_to :group has_many :users, :through => :group end The SQL generated for the search is incorrect: SELECT users.* FROM users INNER JOIN group ON users.group_id = groups.id WHERE
2006 Jan 20
1
stack level too deep from has_many / belongs_to relationship
I have the following 3 models (2 models joined by an intermediate): 1. class Exercise < ActiveRecord::Base 2. has_many :routines, :class_name=>''RoutineExercise'' 3. end 1. class Routine < ActiveRecord::Base 2. has_many :exercises, 3. :class_name=>''RoutineExercise'', 4. :order=>''position'' 5. end 1. class
2006 Jul 25
1
save trouble with has_many belongs_to relationship
I have a bit of code in a controller that looks like this: @current_festival.monitor_preferences.each do |pref| if pref.user_id == @me.id pref.preference = params[:monitor_pref] #pref.save end end @current_festival.save_with_validation(false) the Festival class has_many :monitor_preferences the MonitorPreference class belongs_to :festival In the configuration above, the
2005 Dec 23
2
has_many and belongs_to relationship error
Hi i am getting following error ActiveRecord::StatementInvalid in Blog#index Showing app/views/blog/index.rhtml where line #10 raised: Mysql::Error: #42S22Unknown column ''posts.user_id'' in ''where clause'': SELECT * FROM posts WHERE (posts.user_id = 4) Extracted source (around line #10): 7: <div class="separator">&nbsp;</div> 8:
2006 Apr 26
2
two layers of has_many
Hi, There are many companies. Each company has many departments. Each department has many employees. The following find_by_sql method seems awful. What is the best way to get all the employees of a company? class Company < ActiveRecord::Base has_many :departments def employees Employee.find_by_sql("SELECT employees.* FROM companies, departments, employees
2006 Jan 31
2
Relationship navigation issue
class Event < ActiveRecord::Base belongs_to :venue belongs_to :category end class Venue < ActiveRecord::Base belongs_to :city end class City < ActiveRecord::Base belongs_to :state end I want to retrieve all event records belonging to a state. Coming from hibernate background I tried something like this: def self.list_for_a_state(state_id) find_by_sql(["select e.*
2006 Apr 24
0
Updating a form containing array of text fields with has_many/belongs_to relation?
I''ve got a User class and an Employer class set up as follows: User.rb: has_many :employers Employer.rb belongs_to :user My tables are as follows: mysql> select id,first_name,last_name from users limit 5; +-----+------------+-----------+ | id | first_name | last_name | +-----+------------+-----------+ | 711 | Patrick | Stewart | | 714 | Larry | Davis | mysql>
2006 Jun 02
4
Ruby on Rails Performance question
I''m wondering if this is a typical thing. What I''m doing is getting about 5000+ records from a database and displaying all of it on a page. I''ve used the benchmark helper to benchmark the views for that page and that takes about 25 seconds to render that view. Is this pretty typical? What I''m doing is using find_by_sql to get all the values that I need from
2011 Feb 07
2
Search HABTM relationship in ActiveRecord
Consider the following scenario: Book has_and_belong_to_many Category. In other words, a category may have a lot of books, and a book can have more than one category. What is the best practice to query all books related to some specified categories. For example, if I have following books "From Java To Ruby" - Category: Java, Ruby "Ruby Programming" - Category: Ruby
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 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
2005 Mar 02
0
Using a params from down the model relationship tree
Hi, I have three models: class Product < ActiveRecord::Base has_many :parts end class Part < ActiveRecord::Base has_many :part_applications belongs_to :product end class PartApplication < ActiveRecord::Base belongs_to :part end In a controller, I have access to a Product.id: @product = Product.find(@params[''id'']) So with that I am able to do something like
2007 Oct 07
0
Rails AR/Oracle Unit Test: [7769] failed (getting worse)
"bitsweat" has kicked AR/Oracle while it was down... http://dev.rubyonrails.org/changeset/7769 ------------------------------------------------------------------------ r7769 | bitsweat | 2007-10-06 22:29:37 -0700 (Sat, 06 Oct 2007) | 1 line MySQL: speedup date/time parsing. ------------------------------------------------------------------------ U
2006 Jul 31
0
Issues with has_many, belongs_to and dependency settings
I have 2 models SmsAddress & OutboundSmsAtom SmsAddress { has_many :other_objects, :dependency => :nullify } OutboundSmsAtom { #note this object also "belongs_to" other objects if that matters belongs_to :this_object } Whenever I try to destroy an object of type ThisObject, which at the time has 0 "children" OtherObjects I get the following type of
2006 Jul 31
0
Polymorphic has_many association through a belongs_to
Hi, Let''s say I''ve the following Models and their relative associations: Seat ---- belongs_to :booking Booking ------- has_many :seats has_many :debits, :as => :chargeable Debits ------ belongs_to :chargeable, :polymorphic => true Why >> seat.booking.debits nil while >> Booking.find(seat.booking_id).debits [] ? Thanks. Cheers, Marco
2006 Apr 16
1
has_many :through and belongs_to
I have a relationship where a Show has_many Techs through People. From what I understand that requires me to put belongs_to Show in the People model. My problem is that a Tech can belong to many Shows. Is there any way of solving this besides putting a has_many Shows relationship in People -- Posted via http://www.ruby-forum.com/.
2009 Jan 22
0
ActiveLdap belongs_to and has_many associations
Hi, I am trying to use ActiveLdap for authentication in my rails app. But I am running into a problem with the "belongs_to" and "has_many" associations. Here ist how my models look like. class Person < ActiveLdap::Base ldap_mapping :dn_attribute => "uid", :prefix => "ou=People", :classes =>
2005 Apr 18
1
belongs_to / has_many multiple validation errors
Hi, when using the following code in my model I get 2 errors for only 1 field. belongs_to :category validates_presence_of :title, :message => "required field missing" Then when I test the validation by creating a record without a title I''m told that the title field is missing twice. Please help as this has has me stumped for a few days now. Many Thanks Kieran
2006 Jul 31
2
ambiguous column name in has_many :through
In my application model I have three classes: Accounts, Projects, and Items class Accounts < ActiveRecord::Base has_many :items, :through => :projects, :source => :items has_many :late_items, :class_name => ''Item'', :through => :projects, :conditions => [''due_on < ?'', Time.now], :source => :items end class Projects <
2012 Jan 08
1
Advanced has_many and belongs_to model joins ?
Hi, I''m having major trouble with a somewhat self-referencing has_many and belongs_to set of models. item.manufacturer correctly returns an object of type Vendor. However, item.manufacturer.name raises an exception even though the name value is set correctly. I''ve been debugging and googling and responding to stack overflow peeps but still to no avail. Complete details here: