Displaying 20 results from an estimated 500 matches similar to: "bypass defualt scope."
2024 Oct 07
1
Optimizar bucle for
Hola a todos:
Tengo un bucle que tarda horas y me gustaría optimizarlo. Me explico. Simplificando, tengo una tabla con 332.505 registros de 63.738 individuos. Cada registro es una medida realiza de unos
días a unos meses o años después de la anterior. Lo que quiero es borrar aquellos registros que entre él y el anterior hayan transcurrido menos
de 6 meses, de manera que me quede una tabla con
2024 Oct 07
1
Optimizar bucle for
Hola, ¿qué tal?
Modifica esto:
----
library(plyr)
n_reg <- 332505
n_ids <- 63738
dif_days <- 90
df <- data.frame(
id = sample(n_ids, n_reg, replace = T),
dates = sample(1000, n_reg, replace = T)
)
# important!
df <- df[order(df$id, df$date),]
n_borrar <- 1
while (n_borrar > 0) {
df <- ddply(df, .(id), transform, delta = c(1000, diff(dates)))
# find the
2024 Oct 07
1
Optimizar bucle for
Muchas gracias, Carlos, por esta ayuda!
Desconocia la existencia de ddply y me cuesta interpretar el código. Estoy en ello.
Realmente es mucho, pero mucho, más rápido.
El problema es que si lo aplico a la tabla dde pruebas:
id dates
1 1 2023-01-01
2 1 2023-05-15
3 1 2023-12-01
4 2 2023-01-01
5 2 2023-04-01
6 2 2023-12-01
7 1 2023-03-15
8 3 2023-01-01
dif_days <- 180 #
2012 Jul 05
2
Addition to has_many - a ':source_scope' option
Was looking to work on a small addition (to has_many) which will be useful
to me and others alike. A few technical details about the addition:
Basically wanting to have something like,
has_many :subscribers, through: :subscriptions, *source_scope:* :deleted
We currently have to do this in our code as,
has_many :subscribers, through: :subscriptions, conditions:
2024 Oct 07
1
Optimizar bucle for
Prueba así:
---
dif_days <- 180 # Cambiado 6 meses
df <- data.frame(
id = c(1, 1, 1, 2, 2, 2, 1, 3),
dates = as.Date(c("2023-01-01", "2023-05-15", "2023-12-01", "2023-01-01",
"2023-04-01", "2023-12-01", "2023-03-15", "2023-01-01"))
)
# important!
df <- df[order(df$id, df$dates),]
n_borrar
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
2011 Feb 02
6
how to set default_scope for the whole application?
I know I can set default_scope for individual active record model, but
can I set one up for the whole application?
thanks
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
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
2013 Apr 08
1
cattr_accessor and Thread.current prblems
Hello,
I am trying to convert three applications to multitenant, all of them have
same structure difference is only in little functions and template designs.
All of them using cattr_accessor for setting currencies and other data, and
it works perfectly
Now i added app_id as cattr_accessor to App model to use it in
default_scope to implement multi-tenancy
class App < ActiveRecord::Base
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 Sep 13
0
unscoped option for associations?
Hi all,
I recently encountered a problem in my FriendlyId plugin where a
belongs_to association unexpectedly failed to load because a user was
using state_machine and a default scope to make only "active" records
return by default.
It seems logical to allow associations to be specifed as "unscoped" in
order to bypass any default scopes. Conceptually I see this as similar
to
2009 Dec 28
2
Override .find, .find_by_id, etc...
I read these:
http://www.ruby-forum.com/topic/185297#new
http://www.freezzo.com/2008/05/14/override-default-find-conditions-for-model/
it works, it override the .find perfectly, however it does not cover
.find_by_id or other .find_by_XXX
Is there anyway to override all the find function of a modal? I want to
set the default "select" for User modal, only return name and id, but
not the
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
2011 Jul 11
2
Can't get this Rspec test to pass
Hello,
I''m completely new to Rspec testing and I''m finding it very difficult to
mock specific objects.
In this test, I have a before block setup as such:
[code]
before do
setup_controller_for_warden
controller.session[:operation_id] = 1
@operator = Factory :operator
sign_in :operator, @operator
@persist_herd = Herd.new
2013 Jan 08
0
[LLVMdev] [cfe-dev] LTO "bug" and Clang warnings
On Tue, Jan 8, 2013 at 7:29 PM, Renato Golin <renato.golin at linaro.org>wrote:
> On 8 January 2013 16:53, David Blaikie <dblaikie at gmail.com> wrote:
>
>> I'm not sure what you mean by "fix user's stupidity" here - could you
>> clarify?
>>
>
> Buffer overrun on foo[20] and relying on it for bar[20].
>
> It might not even be an
2010 Dec 23
6
Difference between rake test:units and individually running ruby -I test test/unit/something_test.rb ?
Here''s my issue: running ruby -I test test/unit/something_test.rb for
each of my unit tests works perfectly.
However, running rake test:units brings errors in all of them - some
object becomes nil for some reason.
Why might this be happening?
Specifics: the object that is successfully not nil when I run the unit
tests one-by-one but becomes nil when I do rake test:units is defined
like
2006 Nov 21
5
acts_as_ferret with STI models
Can acts_as_ferret search only one of the inherit models in the
hierarchy of STI models? Say you have Contents, with types articles and
comments. I know that you do Contents.find_by_contents, but can you
also create indexed for Comment and Articles?
Thanks for you help
Miguel
--
Posted via http://www.ruby-forum.com/.
2013 Jan 08
4
[LLVMdev] LTO "bug" and Clang warnings
On 8 January 2013 16:53, David Blaikie <dblaikie at gmail.com> wrote:
> I'm not sure what you mean by "fix user's stupidity" here - could you
> clarify?
>
Buffer overrun on foo[20] and relying on it for bar[20].
It might not even be an error to access foo[50] even though foo only has 20
elements (via pointer indirection rules), but it's user error to do so,
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 =
2009 Oct 17
2
Skip default_scope when running migrations
Hi,
I was wondering if there is a way to skip the application of a
named_scope to calls made in legacy migrations. I am working with some
old migrations that include some data manipulation tasks, and my default
scope is preventing those migrations from running. I''m trying to avoid
editing those migration files with with_exclusive_scope.
Thanks,
-G
--
Posted via