similar to: Specify and validate requirements on an ActiveRecord association

Displaying 20 results from an estimated 10000 matches similar to: "Specify and validate requirements on an ActiveRecord association"

2008 Jul 16
2
belongs_to causing endless loop on first call to save!
Hi, I have a situation I''m hoping someone out there may be able to shed some light on. I have a Rails app (2.1.0 on Ruby 1.8.7) with a wizard-based sign up process, that has recently been changed from storing incremental data in the database to having a medium sized object graph living in the user session until the user completes the entire sign up process (this is a business
2009 Feb 26
1
Problem w/ActionWebService and Inheritance in Service Params
I have a service method that takes a PaymentMethod which can either be a CreditCard or a PayPal account. When I request the service and pass one or the other it always comes over as a PaymentMethod; the service doesn''t seem to know that the parameter is really a CreditCard or PayPal. Here''s some sample code that illustrates what I''m talking about more concretely:
2009 Aug 28
2
Association extension method
In my application a user working at a dropzone can manipulate transactions against customer accounts. Here''s my models: class Transaction < ActiveRecord::Base belongs_to :account end class Account < ActiveRecord::Base belongs_to :dropzone has_many :transactions end class Dropzone < ActiveRecord::Base has_many :transactions, :through => :accounts do def
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
2006 Aug 03
12
More than one has_many :through association between the same 2 models
I wonder if you can have more than one has_many :through association between 2 models. For example... I have a model Teacher and a model Class Now, 1 Teacher works in many Classes, right?. So I need a join model like class Work < ActiveRecord::Base belongs_to :teacher belongs_to :class end But I also would like to know if a teacher CAN teach a class before I
2006 Mar 31
6
Adding objects to a :through association
So I''m one of those nasty people building a self-referential habtm-like Association using the funky new :through stuff. This is about users having friends, so here''s my user.rb: class User < ActiveRecord::Base has_many :friendships, :foreign_key => ''user_id'' has_many :friends, :through => :friendships, :source => :friend end And here''s
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 Apr 05
5
Updating attributes in HABTM association
Hi, I am trying to find a way tp update attributes in a habtm association. I am trying to use the code from ticket #2462, but as my association_class_primary_key_name seems to be empty the generated sql code is corrupt. I hope thats not a problem of my model that this variable is empty. What would you recommend to update those attributes (rails 1.1) THANKS!!! -- Posted via
2006 May 17
2
Association data clobbering (foreign keys too?)
Can someone please confirm or correct the following statements? If I have the following tables create table as (id int, [...], b_id int); create table bs (id int, [...], a_id int); create table as_bs (a_id int, b_id int); and the associations woould be defined like this class A << ... habtm :bs belongs_to :b end so my Model A has a habtm collection of Bs *plus* a direct
2006 Apr 16
8
"Cannot convert String to Integer" after using association
So, I''ve written a partial that does some stuff with a given instance of my class "entity". Entity is ActiveRecord. I''m able to retrieve all sorts of data from an @entity, until I do something like: <% for @attribute in @entity.attributes %> <div id="attribute_<%= @attribute.id %>"> <%= render(:partial =>
2008 Nov 19
3
Overwriting / Decorating ActiveRecord association accessor
Hi, I am trying to overwrite the accessor of a has_many association. Basically my class looks like this: class Person has_many :emails has_one :link, :class_name => ''PersonProxy'' def emails_with_link link.emails + emails_without_link end alias_method_chain :emails, :link end Now that works fine if I only access the collection like >>
2006 Jan 02
3
Altering the accessor of an association collection
I want to be able to do something like this (for example): class Person < ActiveRecord::Base has_many :friends def friends(living_in = :uk) # filter based on parameters here end end Is there any way I can redefine the accessor for an association whilst still being able to get the values? Basically, I''m looking for an equivilent of read_attribute() for associations. --
2006 May 27
7
How should I select rows from a join-model based on more than one association?
A concrete example: We''re building a system to organize the information about workshops being held in various conventions. A convention has more than one workshop, and each workshop can be held in more than one convention. Also each workshop has a host, who is specific to a workshop being held in a specific convention. For example, Matz may host an "Introduction to Ruby"
2006 Feb 16
2
simple association question
I have two models, Donor and Contribution, and have has_many and belongs_to set respectively. My question is regarding creation of associated objects. I''ll let the code speak: me = Donor.find(1) contribution = me.contributions.create do |e| e.amount = 164.00 e.category = Category.find(1) end I thought this was valid, but it doesn''t work properly - it appears to
2006 Apr 20
4
Question about Associations
Hi all. Got a stupid-simple question about associations. I have two models - school and course. There are a fixed number of schools (set up in the migration). Each course is assigned a school and a school will be associated with multiple courses... How do I set up the associations? Do (can) I have School :has_one :course and Course :has_many :schools? Does the schools table then get a course_id
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
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 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
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
2007 Apr 20
7
Stubbing Model.new w/ block?
Ok, I followed the advice of the list and moved more code into my model from my controller. When developing tests for this new code, I ran into a problem... My model code creates a receipt object and sets some values on it: @receipt = Receipt.new do |r| r.x = 1 r.y = 2 # etc end I wanted to be able to stub out Receipt.new so that I could set expectations on the methods called on the