Displaying 20 results from an estimated 1000 matches similar to: "New Technique: Subsets of has_many Associations"
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 Jul 11
10
dependent support for has_many through?
Given the following
class Programmer < ActiveRecord::Base
has_many :assignments
has_many :projects, :through => :assignments
end
if I call Programmer#projects.clear, it will delete_all the joining
assignments; however, I have a situation where I''d like the
assignments to get destroyed instead so that their after_destroy
callbacks get called. It would be simple to
2006 Jan 04
3
ActiveRecord delete_all With Sanitized Parameters?
Hi there
I''m trying to delete a set of active record objects based on certain
conditions. I''d like to do something like the following:
Context.delete_all("uri IN (?)", uris)
But delete_all doesn''t allow multiple arguments. Since I don''t have
the IDs for the objects I want to delete, I can''t use delete(id), and
have resorted to this,
2008 Feb 25
6
Review Request for Significant Performance Improvement in ActiveRecord
I''m going through my old tickets, and I found an outstanding ticket
that I''ve put many hours into, and is absolutely critical for a
production project that I''m now updating to Rails 2.0.2. The ticket:
http://dev.rubyonrails.org/ticket/9560
This comes on the tail of:
http://dev.rubyonrails.org/ticket/9497
Which I believed to be the superior improvement due to a very
2006 Mar 29
2
delete_all not resetting auto incement in database
Hey
I''m writing a simple admin interface thats reading user data (skills)
from a comma separated file.
To clear the database before inserting new skills, I use
Skill.delete_all
Then I insert the new values I read from a file. Everything goes well
up to the point where I see that auto-generated ID''s are not starting
from 1. They start off at 840 (responding to the number of
2008 May 28
2
functional testing joins table problem
I have models/controllers
Class Facility
has_many :facilities_services, :dependent => :delete_all
Class Service
has_many :facilities_services, :dependent => :delete_all
Class FacilitiesServices
belongs_to :facility
belongs_to :service
so in my test/functional/facilities_controller_test.rb, I have
post :destroy, :id => 5
which tosses an error...
2006 Jul 26
7
Delete_all causes a deadlock on MSSQL database ???
Hi all,
When i use the ''delete_all'' function to remove a few rows from my
database, it causes a deadlock on the sql server. The delete seems to be
successful, it then redirects to the ''view'' page, and the record does
appear to be deleted as far as the ''view'' rails page shows.
BUT if i go into sql query analyser, i can''t do a
2007 Jan 25
1
has_and_belongs_to won't delete records
Hi,
I have a has_and_belongs_to relationship between 2 objects, order and
product. I''m getting a foreign key violation when trying to delete
Order. Is there a special way of deleting orders without deleting
products? ("has_many" has :dependant => :delete_all.... does
"has_and_belongs_to" have something similar)
Trying:
Order.delete_all
Getting:
Mysql::Error:
2007 Jan 23
2
Understanding :dependent => :delete_all?
I can''t see what''s wrong here but that''s probably just because I''m so
new to Rails! To get right into it... I have 4 tables that look like
this:
Sites
- id
Projects
- id
- site_id
- user_id
Tasks
- id
- project_id
- user_id
Users
- id
The corresponding models:
class Site < ARB
has_many :projects, :dependent => :delete_all
end
class Project <
2010 Nov 24
0
Surprise in (delete_all | clear | destroy_all) on association
Hi,
I was very surprised by difference of delete_all on association vs
model(delegated to relation).
Given TaskFilter.has_many(:qualifiers, :class_name=>''TaskFilterQualifier'')
TaskFilter.delete_all => one DELETE statement
Without :dependent option on "qualifiers" association
TaskFilter.first.qualifiers.delete_all =>
SELECT `task_filter_qualifiers`.* FROM
2006 Jul 10
3
Problem with migrations
I am trying to start my first project after going though the Depot
application in prog prog''s book. For some reason one of my migrations keeps
bombing. I just try to setup a couple tables with some default information
and even with changing the name of the second table and other minor tweaks
it just does not work. I am connected to the db, the first table does get
filled out.
Any help
2012 Nov 08
1
validates_uniqueness_of(*attr_names) w scope not working in unit test
Rails 3.2.8
Very strange , it works in dv mode console , but not in a unit test
class User < ActiveRecord::Base
belongs_to :subdomain
validates_uniqueness_of :email, :scope => :subdomain_id
class UserTest < ActiveSupport::TestCase
def initialize_user
@booboo = FactoryGirl.create(:subdomain, name: "booboo")
@coocoo = FactoryGirl.create(:subdomain, name:
2006 Jul 27
0
CRUD, REST and associations
Let''s say I have the model class Reader and Magazine, connected by join
model Subscription. It looks something like this
class Reader < ActiveRecord::Base
has_many :subscriptions, :dependent => :delete_all
has_many :magazines, :through => :subscriptions
validates_presence_of :name
end
class Magazine < ActiveRecord::Base
has_many :subscriptions, :dependent =>
2007 Jun 07
4
checking associated objects have been deleted
I have the following model:
class Book < ActiveRecord::Base
has_many :taggings, :dependent => :delete_all
has_many :tags, :through => :taggings
end
is it possible to check that associated taggings are being destroyed
using mocks? I don''t want to test that rails is deleting the
associations, I want to test that I have specified the association as
a dependent one.
the only
2008 Apr 24
3
how to delete all document from the DB (without deleting the DB itself)
Hello,
I'm still testing PHP5 bindings and I could'nt find a way to delete
all documents from a DB without deleting other informations stored in
the DB such as synonyms.
Since the process of adding synonyms is time consuming, I would like
to use the same DB but restart my test without any document in the DB,
is this possibile?
I could'nt find a delete_all or a method like that, nor
2006 Aug 18
4
Button on view
Hi,
I have a page containing 3 views (2 are partials). One of the partials
needs to have a button that will clear a table called "messages" in the
database.
I can put a button like this "<%= button_to "Clear Messages", :action =>
''clear_messages'' %>" and have the controller do "Message.delete_all".
But the problem is that the
2007 Sep 24
3
Trouble using backgroundrb
Hi all,
I''m a newbie to backgroundrb and am having trouble integrating it into
my rails-app. I''m using namespaces to differentiate between the parts of
my app.
When I want to create a new worker, it seems that it cannot find the
worker object. Here''s my code:
-------------------- controller app/passwd/index --------------------
class Passwd::IndexController <
2006 May 17
0
teardown not cleaning the BD?
Hi,
I am a bit confused, I have a few functionnal tests were I add/delete
records on top of the ones provided in the fixture and it seems like the
records are surviving the teardown. Isnt teardown supposed to be ran
after each test? So if I have something like:
def teardown
Client.delete_all
Concept.delete_all
Variation.delete_all
ClientVariation.delete_all
end
All the
2006 Jul 10
2
Problem with migrations, postgresql, AWDwR
Hi all,
Rails 1.1.4
Rake 0.7.1
PostgreSQL 8.1.4
Windows XP Pro
I checked for errata on pragmaticprogrammer.com, but didn''t see any
explicit mention of this issue.
I''m going over the depot example in AWDwR, 2nd ed, and I can''t get the
migration to work on p. 82. Specifically, the AddTestData example (with
reduced description text to save my fingers some typing):
2009 Oct 14
0
[PATCH server] hack betternested set to enable pool deletion
This is an ugly hack to fix the betternestedset plugin as currently
a bug does not allow pools to be deleted. The single line commented
out in this patch deletes the pool itself instead of only its children
for whatever reason.
This wouldn't be a problem were it not for the recent
change to active record which enforces optimistic locking upon
destroy operations. Since the database record is