Displaying 20 results from an estimated 11000 matches similar to: "ActiveRecord has_many associations"
2011 Jul 28
2
RSpec, shoulda-matchers and Rails model attributes validations
I was trying out RSpec framework in a project and got stopped doing the unit
test of a model. In particular, doing the test for the associations and the
ActiveRecord validations.
I started writing the validations but my tests didn''t look DRY at all.
Before refactoring the tests checked out and look for other people
solutions.
I found out shoulda-matchers and Shoulda (which if I
2011 Aug 02
4
Best way to test tasks
I have a task that runs frequently in order to get/import data from another
system.
Because of this I wanted to know which is the best way to test tasks in
order to create the tests needed.
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110802/315d630f/attachment.html>
2006 Jul 20
5
How can I make has_many prevent a delete that would lead to orphans?
e.g.
class Asset < ActiveRecord::Base
validates_presence_of :asset_number, :make, :model, :location,
:name, :serial_number
validates_numericality_of :asset_number
validates_uniqueness_of :asset_number
belongs_to :user
belongs_to :location
belongs_to :asset_type, :foreign_key => ''type_id''
end
class Location < ActiveRecord::Base
validates_presence_of :name
2011 May 31
1
Calendars in Rails
Hi all,
I''m currently in the need to implement a calendar in rails.
It should be able to present a year, month and day view.
The events in these 3 views should be able to be opened, on click, to view
the information and/or edit it (according to restrictions).
The events will belong to users. One requirement is that users could filter
which other users events they want to see (different
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/.
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 Apr 04
1
Manipulating has_many :through associations
Hi,
I haven''t done any associations before, so please forgive my incorrect
use of terminology...
If I set up a has_many :through association, can I manipulate the
associated instances directly (like an Array), or do I need to
manipulate the join model?
For example, suppose I have two classes and the associated join model:
class foo
has_many :foo_bars
has_many :bars, :through
2006 Feb 03
1
nested has_many associations
My question is whether the rails helper methods for handling associations can
be nested (see examples below). I suspect not as currently I''m
getting "unknown method" if I try and use two associations in one call.
The essence of the code is
class User << ActiveRecord::Base
has_many :items
class Items << ActiveRecord::Base
has_many :reservations
belongs_to
2011 Aug 03
2
How to test modules and custom validators
I''m trying to have most of the important stuff tested and in order to do
that I run in front of some stuff I''m not quite sure which is the best way
to test them.
At this time I am having question around how to test modules and the custom
validators (the typical email format validator for example).
To test a module the best I saw up to now was finded here:
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 =>
2006 Aug 16
1
Naming rights_roles join model using has_many :through and polymorphic associations
Hi.
I have a couple of best practices questions regarding polymorphic
associations, naming join tables and user permissions.
Currently I have implemented the user authentication model from the
rails recipes book. Basically it goes something like this:
MODEL CLASSES:
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
end
class Role < ActiveRecord::Base
2006 Mar 24
2
Change to has_many :through associations
Hi everyone. I''ve made a default change to has_many :through
associations that I felt was important to make before they''re
released. This is after some tickets and confusion I''ve seen
regarding has_many :through.
class Connection < ActiveRecord::Base
belongs_to :user
belongs_to :channel
end
class Channel < ActiveRecord::Base
has_many :connections
2006 Jun 13
0
question about saving associations when using has_many :through
I''ve got a User model and a Book model. A user is required to submit
books each month to be reviewed by other users. I have the following
relationships defined:
# the join model
book_review.rb
belongs_to :user
belongs_to :book
end
book.rb
# each book is reviewed by many users. This allows us to get the BookReview
# objects associated with this book
has_many :book_reviews,
2010 Mar 24
1
How to stub a has_many relationship in Rails 2.3.5
We have a test that has been working find until we upgraded to rails 2.3.5.
I''m not too familiar with mocks/stubs so maybe there is an easy solution.
Here is a simple example of our scenario.
Class Person < ActiveRecord::Base
has_many :aliases, :dependent => :nullify
before_destroy :mark_aliases_as_deleted
def mark_aliases_as_deleted
self.aliases.each do
2006 Aug 17
0
Editiing multiple has_many associations at once
I am search for a nice tidy solution to the following or if only to talk
the problem out aloud.
I have three tables
products
has_many :pricings
pricings
belongs_to :product
belongs_to :pricing_group
pricing_groups
had_many :pricings
I would like to have a single page where I can add/edit a product and on
the same page administer the pricing for that product for each pricing
group.
2006 Aug 01
3
Validation on ActiveRecord destruction
Rails has many built in validation methods to ensure that an
ActiveRecord instance cannot be created or updated under certain
situations (typically caused by invalid data). However, I can find no
methods to govern whether an ActiveRecord instance can be destroyed.
Essentially, I wish an error to be raised when a user tries to delete an
ActiveRecord without first adhering to a certain set of
2006 May 16
2
Validate Before Delete
I have an Order model with a ''status'' column. What I want to be able to do
is validate that the status of the Order is not completed before it is
allowed to be deleted. I tried the following method in my Model, but it
appears that this only works for an :update or :create on the record.
Anyone know how to do this, and if it should be in the model or the
controller?
2008 Apr 24
2
Dynamic finders in has_many associations
I have these 3 models.
class Ivr < ActiveRecord::Base
has_many :klusterings, :dependent => :destroy
has_many :klusters, :through => :klusterings, :uniq => true
end
class Kluster < ActiveRecord::Base
has_many :klusterings, :dependent => :destroy
has_many :ivrs, :through => :klusterings, :uniq => true
end
class Klustering < ActiveRecord::Base
belongs_to :kluster
2006 Apr 14
1
ActiveRecord and multiple associations
Hello,
I have a Company that has_and_belongs_to_many Persons. A Person
has_many Emails. I want to display each Person''s Email for each
Company, so I try this:
companies = Company.find(:all)
for company in companies
persons = company.persons
for person in persons
puts person.email
end
end
Unfortunately, this doesn''t work correctly. Let''s say the id of
2006 Jan 21
2
Testing ActiveRecord associations
How do I write a test which proves something like "Post :has_many
Comments" and "Comment :belongs_to Post"? It doesn''t seem to be covered
in "A Guide to Testing the Rails" on manuals.rubyonrails.com.
Cheers, Robert.
--
Posted via http://www.ruby-forum.com/.