[Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread matthewrudyjac...@gmail.com
On May 12, 10:29 pm, Matt Jones wrote: > I've run across this before too, but I used something like this: > > %w(Admin Manager Candidate).each { |c| c.constantize } > > As I can never remember which one of require / require_dependency > sometimes jams up (or used to back in the day) the autoload

[Rails-core] OT? Using Arel to generate table names in multiple self join query

2010-05-12 Thread Pietro
Firstly I'm sorry if this is off-topic but I think it's a question that won't be answered without good core knowledge. I have written a multiple self join query something like this: Person.find :all, :select => 'children_people_3.*', :joins => { :children => { :children => :children } }, :c

Re: [Rails-core] feedback on a few ActiveSupport::Multibyte patches

2010-05-12 Thread Rodrigo Rosenfeld Rosas
HEm 12-05-2010 13:02, Norman Clarke escreveu: On Tue, May 11, 2010 at 16:51, Rodrigo Rosenfeld Rosas wrote: Norman, I checked out your multibyte branch but it is not working for me. Here is what I did: $ cd ~/src/rails $ git remote add norman http://github.com/norman/rails.git $ git remo

[Rails-core] rails is removing constants which it is not able to restore properly in development mode

2010-05-12 Thread Neeraj Singh
I have updated ticket https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4149-strange-require-behavior-in-development-environment#ticket-4149-10 with my thoughts. Would appreciate any comments on how to go about resolving the issue in dependencies.rb . -- You received this messa

[Rails-core] Re: Loading files in Rails lib folder?

2010-05-12 Thread Kristian Mandrup
Yes, it worked by inserting the require statements in the initializers. On May 12, 12:00 pm, Kristian Mandrup wrote: > How does the lib folder work in Rails 3? > > In Rails 2.x you would add require statements in application.rb, fx: > > /lib >   blip.rb > > # blip.rb > puts "BLIP" > > # applicati

[Rails-core] Re: Loading files in Rails lib folder?

2010-05-12 Thread Kristian Mandrup
OK, it seems it works using autoload, being lazy loaded when accessed. But what if I want to force it to be loaded when rails starts? Appending a require 'blip' in application.rb I am told no such file exists!? Would I have to insert it in an initializer? # lib/blip.rb puts "Blip loaded!" class

Re: [Rails-core] feedback on a few ActiveSupport::Multibyte patches

2010-05-12 Thread Norman Clarke
On Tue, May 11, 2010 at 16:51, Rodrigo Rosenfeld Rosas wrote: > Norman, I checked out your multibyte branch but it is not working for me. > Here is what I did: > > $ cd ~/src/rails > $ git remote add norman http://github.com/norman/rails.git > $ git remote update > $ git checkout norman/multibyte

[Rails-core] Loading files in Rails lib folder?

2010-05-12 Thread Kristian Mandrup
How does the lib folder work in Rails 3? In Rails 2.x you would add require statements in application.rb, fx: /lib blip.rb # blip.rb puts "BLIP" # application.rb ... require 'blip' --- But using the same approach doesn't work in Rails 3. How do I configure this so that blip.rb is loaded when

Re: [Rails-core] Re: Trouble developing Rails plugins/gems with generators

2010-05-12 Thread Anuj Dutta
On 12 May 2010 20:58, Kristian Mandrup wrote: > On a further note. I can't seem to get any .rb files in RAILS_ROOT/lib > to load when I start my rails server. > > Say I have a file > > # lib/auth_assistant.rb > puts "Hello from AuthAssist" > > -- > In the old days of Rails 2.3+ you would put a re

[Rails-core] Re: Trouble developing Rails plugins/gems with generators

2010-05-12 Thread Kristian Mandrup
On a further note. I can't seem to get any .rb files in RAILS_ROOT/lib to load when I start my rails server. Say I have a file # lib/auth_assistant.rb puts "Hello from AuthAssist" -- In the old days of Rails 2.3+ you would put a require statement in application.rb, but I think in Rails 3 all fil

[Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Neeraj Singh
Thanks everyone for the input. I understand what's going on now. I will mark ticket #4516 as invalid. On May 12, 10:51 am, Xavier Noria wrote: > On Wed, May 12, 2010 at 4:36 PM, Mislav Marohnić > > wrote: > > When you're querying a parent that doesn't have any non-abstract parent > > (meaning

Re: [Rails-core] Re: Trouble developing Rails plugins/gems with generators

2010-05-12 Thread Anuj Dutta
On 12 May 2010 20:49, Kristian Mandrup wrote: > On another note: > > I would like to have available the methods used in Rails 3 templates. > I see many generators including Rails::Generators::Migration and using > the method migration_template to create a new migration. > What I would like is for

[Rails-core] Re: Trouble developing Rails plugins/gems with generators

2010-05-12 Thread Kristian Mandrup
On another note: I would like to have available the methods used in Rails 3 templates. I see many generators including Rails::Generators::Migration and using the method migration_template to create a new migration. What I would like is for my generator to create the options for running a basic mig

Re: [Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Xavier Noria
On Wed, May 12, 2010 at 4:36 PM, Mislav Marohnić wrote: > When you're querying a parent that doesn't have any non-abstract parent > (meaning he's the top of the STI hierarchy), then theoretically you really > don't have to know the list of descendants. AR could just make a query > without conditi

Re: [Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Mislav Marohnić
When you're querying a parent that doesn't have any non-abstract parent (meaning he's the top of the STI hierarchy), then theoretically you really don't have to know the list of descendants. AR could just make a query without conditions. I think it would be a good addition to AR. Or am I missing s

Re: [Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Matt Jones
On Wed, May 12, 2010 at 8:50 AM, Mislav Marohnić wrote: > Isn't the problem obvious? ActiveRecord cannot list all subclasses under STI > until it loads all modes in the app. In development mode it relies on > autoloading and never preloads all models. > The local solution: require statements in th

Re: [Rails-core] Re: Trouble developing Rails plugins/gems with generators

2010-05-12 Thread Anuj Dutta
On 12 May 2010 19:55, Kristian Mandrup wrote: > I worked it out myself. It had to do with the fact that the generators > for some reason require the namespace to match a containing folder, > much like the Java package mechanism. > > lib/generators > - auth_asisst > - ability > ability_gene

[Rails-core] Re: Trouble developing Rails plugins/gems with generators

2010-05-12 Thread Kristian Mandrup
I worked it out myself. It had to do with the fact that the generators for some reason require the namespace to match a containing folder, much like the Java package mechanism. lib/generators - auth_asisst - ability ability_generator.rb # ability_generator.rb module AuthAssist module G

Re: [Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Colin Law
On 12 May 2010 14:50, Neeraj Singh wrote: > User.find_by_name 'agent' generates a sql that does not use Agent or > SuperAgent even if they are loaded. > > However the behavior of Agent.find_by_name 'agent' is different if > SuperAgent is loaded. > > @Colin: SuperAgent should be a subclass of Agent

Re: [Rails-core] Trouble developing Rails plugins/gems with generators

2010-05-12 Thread Anuj Dutta
On 12 May 2010 19:33, Kristian Mandrup wrote: > Hi, > > I've been trying to develop a Rails gem/plugin with generators for > Rails 3. I first had a separate gem project with a gem statement in my > Gemfile with a :path option to point at it. But then I had to run $ > rake install on each change i

[Rails-core] Trouble developing Rails plugins/gems with generators

2010-05-12 Thread Kristian Mandrup
Hi, I've been trying to develop a Rails gem/plugin with generators for Rails 3. I first had a separate gem project with a gem statement in my Gemfile with a :path option to point at it. But then I had to run $ rake install on each change in my gem to have Rails pick up on it. I have now instead pu

Re: [Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Xavier Noria
In general, if you have grandchildren you need to load them to ensure they are known. I compute them this way: http://gist.github.com/274219 The bottom line is that Active Record needs to know the STI hierarchy that is relevant to any given query. That just does not play nice with autoloading

[Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Neeraj Singh
User.find_by_name 'agent' generates a sql that does not use Agent or SuperAgent even if they are loaded. However the behavior of Agent.find_by_name 'agent' is different if SuperAgent is loaded. @Colin: SuperAgent should be a subclass of Agent. I have updated the gist with this info. @Mislav: Yes

Re: [Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Colin Law
On 12 May 2010 13:50, Mislav Marohnić wrote: > Isn't the problem obvious? ActiveRecord cannot list all subclasses under STI > until it loads all modes in the app. In development mode it relies on > autoloading and never preloads all models. > The local solution: require statements in the end of "u

Re: [Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Mislav Marohnić
Isn't the problem obvious? ActiveRecord cannot list all subclasses under STI until it loads all modes in the app. In development mode it relies on autoloading and never preloads all models. The local solution: require statements in the end of "user.rb": require 'manager' require 'agent' So w

Re: [Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Colin Law
On 12 May 2010 13:33, Colin Law wrote: > On 12 May 2010 12:56, Neeraj Singh wrote: >>> Since you have deleted all of the original post and my comments the >>> above now makes no sense.  No-one reading this will know what your >>> problem is without going back to the previous mail, which is someth

Re: [Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Colin Law
On 12 May 2010 12:56, Neeraj Singh wrote: >> Since you have deleted all of the original post and my comments the >> above now makes no sense.  No-one reading this will know what your >> problem is without going back to the previous mail, which is something >> one should not normally be forced to d

[Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Neeraj Singh
> Since you have deleted all of the original post and my comments the > above now makes no sense.  No-one reading this will know what your > problem is without going back to the previous mail, which is something > one should not normally be forced to do. Extremely sorry about that. I have created

Re: [Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Colin Law
On 12 May 2010 11:42, Neeraj Singh wrote: > The sql that I posted came out after testing the exact case provided > by the author of the ticket. While composing this email I did not > layout the full hierarchy. > > @Colin. It is definitely due to class loading. If in development I > load Agent then

[Rails-core] Re: In development mode not all types are included in the query related to type

2010-05-12 Thread Neeraj Singh
The sql that I posted came out after testing the exact case provided by the author of the ticket. While composing this email I did not layout the full hierarchy. @Colin. It is definitely due to class loading. If in development I load Agent then query will include Agent too. script/console > Agent

Re: [Rails-core] In development mode not all types are included in the query related to type

2010-05-12 Thread Colin Law
On 12 May 2010 04:47, Neeraj Singh wrote: > class User > end > > class Agent < User > end > > script/console production > User.find_by_name 'john' > > SELECT "people".* FROM "people" WHERE ((("people"."type" = 'User' OR > "people"."type" = 'Manager') OR "people"."type" = 'Agent')) AND > ("people".