Displaying 20 results from an estimated 7000 matches similar to: "Skip default_scope when running migrations"
2009 Jul 11
2
offeride :limit named_scope default_scope
Hi,
Rails 2.3.2
class TestD < ActiveRecord::Base
default_scope :limit => 12
named_scope :limit, lambda { |num| { :limit => num} }
end
ruby script/console
>> TestD.all
TestD Load (0.7ms) SELECT * FROM "test_ds" LIMIT 12
=> []
>> TestD.limit(14)
TestD Load (0.3ms) SELECT * FROM "test_ds" LIMIT 12
=> []
Any ideas why the default limit
2010 Sep 01
4
deprecation warning in Rails 3 about Base.named_scope
I recently upgraded to Rails 3, and this error has come up
ubiquitously:
DEPRECATION WARNING: Base.named_scope has been deprecated, please use
Base.scope instead.
Any ideas on how to get rid of it? Or should I just wait for
something?
There''s actually no place in my application where the code
"Base.named_scope" exists, so I assume the problem is inherent in gems
that
2009 Jul 23
11
Problem with named_scope
Here are my scopes:
default_scope :order => ''posted_on DESC'', :conditions => { :status =>
''visible'' }
named_scope :positive, :conditions => { :rating => ''positive'', :status
=> ''visible'' }
named_scope :neutral, :conditions => { :rating => ''neutral'', :status
=>
2010 Jan 15
1
Chaining queries in ActiveRecord
Hi all,
Stuck at this problem for several days. Tried to use named_scope,
scope_out, and plugin such as searchlogic, but no result.
The problem is as follows: I have a pic table and tag table, and a
join table called pic_tag (with only pic_id and tag_id) so that I can
associate N pics to M tags. This is the tutorial way to set up a many-
to-many association. I''m trying to implement a
2008 May 22
14
Specifying certain tables NOT to be cleared each example?
Is it possible to specify that certain tables not be cleared on each
example.
I''ve inherited a project where a good amount of enumerated data is
stored in the database (US States, statuses, about 15-20 tables worth.
Over all, it''s a reasonable decision that leads to solid production
code (acts_as_enumerated is good). This data is read-only and
relatively static; any
2008 Jun 03
1
Custom counter cache
class Category
has_many :tracks
end
class Track
belongs_to :category, :counter_cache => true
named_scope :converted, :conditions => {:converted => true}
named_scope :active, :conditions => {:active => true}
end
I want to make custom counters for scoped associations, e.g:
category.converted_tracks_count
category.active_tracks_count
And when `track` changes its converted,
2007 Oct 18
9
with_scope issue
I have the following code:
class User < ActiveRecord::Base
has_many :requests do
def find_active(options = {})
with_scope :find => { :conditions => ["requests.active = ?",
true] } do
find(:all, options)
end
end
end
end
Executing user.requests.find_active results in the following SQL:
SELECT * FROM requests WHERE (( requests.user_id = 10 ) AND
(
2006 Apr 02
5
adding primary_key to join table using migrations
Hi list,
My tag_question_user join table is not currently a full-blown model. It
doesn''t have a primary key - just tag_id, question_id, and user_id.
I now want to add a primary key to this model (because I want to add a
"description" column as well so users can describe the tag.
I''m not sure how to add this using migrations.
Here is what I have:
class AddNotesToTags
2010 Oct 04
2
newbie q on activerecord - has_one and has_many on same table?
Hi I have a table where I need to identify one of the children as the
"prime" child.
So, its like:
Parent
has_many :Child
has_one: Child :as :prime_child (?)
or something like that? Do I put something like prime_child_id in the
Parent table?
Thanks.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this
2010 Feb 22
3
Multidimensional dynamic Hash
OK I give up, how do I do this...
I have a DB that stores dynamic variables with I group into
group_id''s. For instance here are a couple examples of db rows:
title="name", description = "john", grouping_id = "1"
title="location", description = "USA", grouping_id = "1"
title="comment", description = "hello",
2009 Nov 01
1
please help - complicated polymorphic association
I am trying to build a shared-appointment system, where users can
subscribe to appointments and be updated whenever changes are made to
them. I have three objects in this system, appointments, users, and
subscribers. Subscribers are a polymorphic object like so:
class Subscriber < ActiveRecord::Base
belongs_to :user
belongs_to :subscribable, :polymorphic => true
end
The tricky part is
2010 Jun 24
3
DRY a named scope
Is there a way to DRY this up a bit?
named_scope :has_valid_sysoid, lambda{|sysoid|
(sysoid.nil?) ? {:conditions => ["nodesysoid IS NOT NULL AND
nodelabel LIKE ''%-to-%''"], :include => [:ipinterface, :alarm]} :
{:conditions => ["nodesysoid IS NOT NULL AND nodelabel LIKE ''%-to-%''
AND nodesysoid = ? ", sysoid], :include =>
2010 Feb 11
3
Parameterized ActiveRecord Associations: Any such thing?
Hi list, how are ya?
So, my current project is just begging for the ability to have
parameterized associations in my ActiveRecord classes. Basically I
need something that is a cross between named scopes and standard
associations (has_many specifically).
I''m wondering if such a thing exists or, if not, if anyone else has an
elegant, equivalent solution?
Example:
class Sprocket <
2008 May 13
6
Testing that named_scope is defined
Hi guys,
I''m just beginning to use RSpec and I ran into the issue of testing a
named_scope. I''m not actually trying to test its behavior, as it''s not
my code, but I wanted to test at least that it''s defined. I tried
doing this:
describe Post, ".most_recent" do
it "should be defined" do
Post.method_defined?(:most_recent).should be_true
2009 Oct 27
5
Re-tasking destroy contoller action...is this bad practice?
I''m trying to get some opinions on a design I''m floating ("rails way"
or not?). Say I''ve got an Author model in my Blog application and I
want my administrators to be able to disable authors. I don''t want to
delete authors because this would cause data integrity issues
(orphaned Author foreign key in the Post model). So my plan is to re-
task the
2013 Jun 15
1
A puzzle about default_scope
Hi, guys
I have a puzzle about default_scope.
Suppose I have two model:
class User < ActiveRecord::Base
has_many :blogs
default_scope where(deleted_at: nil)
end
class Blog < ActiveRecord::Base
belongs_to :user
end
I want to produce sqlselect blogs.* from blogs inner join users on users.id
= blogs.user_id and users.deleted_at is null
And the code Blog.joins(:user), which I think
2012 Jul 25
0
Rails3-default_scope throws exception: undefined method abstract_class? for Object:Class
I would like to apply logical delete in my application(Instead of
permanently deleting a record just have been marked as deleted). I have
Added *available* column to all tables with default value *true*. Now I
want common place to write the following code for all models.
1.
Write the instance method which make ''available'' column value false when user clicks on
2009 Jul 05
4
Deploying without capistrano, using git pull?
I''m NOT working on an enterprisey big time rails application; just
something for my personal site.
I''ve been deploying via
local> git push origin master
remote> git pull origin
remote> sudo /etc/init.d/httpd restart
Trying to decide if this is sufficient, or if learning capistrano and
setting that up will give me any advantages over this?
Thanks,
Dave
2010 Mar 04
25
how to share variables in data migrations (up/down)
hi there,
How do we share variables in a given data migration?
For example,
the code below fails to work because "statuses" don''t seem to be in
scope for both up and down.
class AddDefaultValuesToStatuses < ActiveRecord::Migration
statuses = [
{
''details'' => ''details'',
},
{
2010 Jan 05
2
Conditional named_scope chaining with params (Need help)
Hello there,
I have a model that has more then one named_scope.
In my action Index of the controller that handle this model I want to do
this in a drier way:
if params[:ownership] == "mine"
@posts = Post.tagged_with(params[:tags], :on =>
:tags).owner(current_user.id).paginate :all, :page => params[:page],
:order => ''created_at DESC''
else