similar to: ActiveRecord, has_many association and object graphs

Displaying 20 results from an estimated 10000 matches similar to: "ActiveRecord, has_many association and object graphs"

2010 Aug 29
4
Wrong class being returned in association
I''m using Rails 3.0.0rc and have the following models: class User  has_many :readings  has_many :conversations, :through=>:readings end class Reading  belongs_to :user  belongs_to :conversation end class Conversation  has_many :readings  has_many :users, :through=>:readings end and this controller code: class ConversationsController  def show    @user =
2008 Apr 11
2
Validating an ActiveRecord object and its has_many :through associations
Considering an object with several has_many :through => associations, what is the ''best'' way to handle validations? As an example: class Student < ActiveRecord::Base # some attrbutes like # :name # :grade # relationships has_many :students_assignment, :dependent => :destroy has_many :assignments, :through => :students_assignment has_many
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 May 05
0
Missing documentation for find_in_collection? Trying to drill down in a 4 level has_many association fails
I''ve been reading up in ActiveRecord::Associations and playing around with my app via the console and found some interesting methods via the code completion of IRB, but I have no idea how to use them and can only find one hint in the API http://api.rubyonrails.com/classes/ActiveRecord/Associations/ ClassMethods.html It mentions here in the has many associations that if you use the
2011 Jul 26
1
ActiveRecord has_many associations
Given the models Country, State, City and Person as follows. class Country < ActiveRecord::Base has_many :states end class State < ActiveRecord::Base belongs_to :country has_many :cities end class City < ActiveRecord::Base belongs_to :state has_many :people end class Person < ActiveRecord::Base belongs_to :city end Is there any way that doesn''t allow to delete
2006 Jun 19
2
const_missing error of has_many through association
Hi, I am new to ruby on rails. I am building an association join model and encountered the following error. Does anyone know what am I missing? > NameError in StartController#home > >d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in `const_missing'': uninitialized constant Membership I have the following tables relationships Users
2006 May 04
0
Complement set association to has_many/through?
I have two models, A and B, with a straightforward many-to-many has_many/through association between them. So, in A I have the association processed_bs and in B I have processedby_as. This works fine. Now, I would like to also have an association unprocessed_bs in A, which holds all Bs that _aren''t_ in processed_bs. I can write a method in A that returns all those objects as a list
2006 Apr 03
0
with_scope used in a has_many :through model
Hi there, I have something like the following: class Person < AR:B ... ... has_many :votes has_many :chosen_answers, :through => :votes, :source => :answer, :select => ''DISTINCT answers.*'' do def my_answers(whodunnit) chosen_answers.with_scope(:find => { :conditions => [ "votes.created_by=?", whodunnit ] }) do chosen_answers.find :all
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 Jun 22
0
how to save objects in a has_many :through association?
(I posted this yesterday but it never showed up on the mailing list... weird.) I recently converted a habtm relationship into one using has_many :through. Some of my old logic relied on the ability to use the #<< operator to add items to the relationship and get them auto- saved. I''m curious to know the best way to do the same operation with the has_many :through
2006 Aug 09
0
select-multiple for has_many association
I haven''t looked into this for several months, but there still doesn''t seem to be an obvious way to generate a HTML select element for choosing multiple items to be set for a has_many association. <select id="person_task_ids" multiple="multiple" name="person[tasks][]"> <option value="1">Do something</option>
2014 Apr 06
0
collection_check_boxes with has_many through: association Rails 4
I am trying to list all the categories a user can be interested in with check boxes so that a user can submit these interests through my join table. collection_radio_buttons works with a simple has_many, belongs_to association: <%= collection_radio_buttons(:listing, :category_id, Category.all, :id, :name do |b| %> <%= b.label { b.radio_button} %> <%= b.text %>
2006 May 10
3
has_many association.
I''m creating a address book. A user can have many contacts. In the user model, I put: has_many :contacts And in the contact model, I put: belongs_to :user To list all contacts, I search as following: @user = User.find(session[:user_id]) And rendering: <%= render(:partial => "contact", :collection => @user.contacts)%> To persist I am using the following
2010 Jun 17
0
Edge Rails Nested has_many :through Association
So this functionality isn''t supported natively in Rails 3 (or any versions before that for that matter) But I had found a work around via this blog post: http://geoff.evason.name/2010/04/23/nested-has_many-through-in-rails-or-how-to-do-a-3-table-join/ This didn''t work on Rails 3 because it wasn''t able to properly build the query from the join with symbols. I was
2012 Jul 10
1
has_many association with autosave issues
I''d like to use autosave => true for an association for its added benefits: the parent doesn''t save unless the children saves. However, it seems to skip validations when saving the children. And this seems to be the case since the beginning of time... Anyone know why? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2006 Jan 30
0
Serializing has_many associations and ActiveRecord objects
Is it possible to serialize ActiveRecord objects and ActiveRecord children to XML? -- Posted via http://www.ruby-forum.com/.
2006 May 08
2
Creating a "Foo has_many bars" association where bar isn''t a model.
Hi Let''s say we have model Foo. Each Foo instance can have several bars. Those bars are primitive, so they shouldn''t be models. For example, Foo might be a type of convention, and the bars might be years the convention was held in. Naively, we would have a conventions_years date, and put: has_many :years inside class Convention. But then we''d get an error, since for
2007 May 22
3
can I use acts_as_list with a has_many :through association
I''d like to be able to use a has_many :through association and treat the associations as a list but I''m getting this error when I try an use an acts_as_list method: NoMethodError: undefined method `move_to_bottom'' I''m using edge rails r6786. Here are my domain rules: Activities are things students can do. Units consists of a sequenced list of
2006 Feb 17
1
validate() with has_many association
I''m creating a simple portfolio site for a painter. I have a painting and an image model with following relationship: Painting has_many :images Image belongs_to :painting On the edit screen the user can edit the Painting data as well as upload pictures for a thumbnails and full size image. The Image model extracts filename, width, and height from the uploaded file, saves those
2006 Apr 19
2
Using Reflections to find out ActiveRecord class association
I want to find out what are the associations with another active record class. So If my class is as below: Class Component < ActiveRecord::Base has_many :branches end class Branch < ActiveRecord::Base belongs_to :component end and then I do Component.reflections[:branches].active_record I would expect that to be Branch but it is in fact Component. The inspection of