Re: [Rails-core] [ann] Super DRY models - Auto-associations and validations

2006-08-15 Thread Martin Emde
On 8/14/06, Andrew Kaspick [EMAIL PROTECTED] wrote:
If all this did was generate the base model with the associations andvalidations then that would definitely relieve some initialdevelopment time and possibily worthy of core inclusion.It can't really be included with script/generate model since it baseswhatitwouldgenerateonthemigrationthatwouldnotbecreatedyet. Some sort of script you could run after the model was created and the migrations were done that would add the code would be pretty nice tho. Maybe even something that you could run multiple times that would (and this might be hard) not step on your toes if youhad already modified the model.
 Martin
___
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core


Re: [Rails-core] [ann] Super DRY models - Auto-associations and validations

2006-08-15 Thread Nic Williams
@Andrew and Kyle: I've started a magic_model_generator that will be released after a foreign key support patch. That'll be a wonderful tool. Not very magical, but useful... non-magically.@DHH and Andrew : I agree with that - in a normal app development, you'll always want a model class and explicit associations - eventually. 
Its probably a style preference for agile developers as to whether they are happy to immediately start work with derived associations (like the derived attr_accessors for fields in ARs now) instead of explicitly defining them. Opinions are great; so is choice. :) 
Over time, we'll start to get feedback on people's development philosophies/strategies, for new Rails apps, Rails apps on legacy DBs, and non-Rails apps, etc.@Rodrigo - Apparently post-Railsconf (read, post-Dave Thomas talk), some work was done on auto-validations by some people which is more magical that the simple validations that are available now; so I'll include those too; 
e.g. validates_uniqueness_of if its a sole-index, etc. Wonderful stuff!CheersNic-- Dr Nic Williamshttp://www.drnicwilliams.com - Ruby/Rails blogskype: nicwilliams
(m) +31 62 494 8552(p) +61 7 3102 3237 (finds me anywhere in the world)(f) +61 7 3305 7572 (sends fax to my email)
___
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core


Re: Re: [Rails-core] [ann] Super DRY models - Auto-associations and validations

2006-08-15 Thread David Heinemeier Hansson

Its probably a style preference for agile developers as to whether they are
happy to immediately start work with derived associations (like the derived
attr_accessors for fields in ARs now) instead of explicitly defining them.
Opinions are great; so is choice. :)


I agree. With Rails, the split is that opinions go into core and
options go into plugins.
--
David Heinemeier Hansson
http://www.loudthinking.com -- Broadcasting Brain
http://www.basecamphq.com   -- Online project management
http://www.backpackit.com   -- Personal information manager
http://www.rubyonrails.com  -- Web-application framework
___
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core


Re: [Rails-core] [ann] Super DRY models - Auto-associations and validations

2006-08-14 Thread Rodrigo Kochenburger

I like this, and i believe most people would.
I can't say for the core team, but i think you sould create a patch
and post it on trac. The automatically validation can be improved to
more than just validates_presence_of as well, others people might help
with that and then it would be easier to apply the patch on the trunk
;)

Nice job, Nic.

Cheers!

Rodrigo Kochenburger

On 8/14/06, Dr. Ernie Prabhakar [EMAIL PROTECTED] wrote:


Hi Nic,

I for one think this is incredibly cool, and would love to see it in Rails
1.2 (as part of core)...

Thanks!
-- Ernie P.

On Aug 8, 2006, at 3:33 AM, Nic Williams wrote:

I've written an ActiveRecord extension that allows Associations to be
automatically generated at runtime without requiring has_many and
belongs_to to be defined in the class. The use of has_many vs has_one is
determined by the pluralisation of the method call.

Additionally, it uses the :null = false attribute of columns to provide
validates_presence_of automatically to models too.

If any of this code is relevant for Core Rails, let me know and I'll extract
it from the gem and create a patch for core. The gem has received a good
reception on the Ruby + RoR forums.

http://drnicwilliams.com/2006/08/07/ann-dr-nics-magic-models/

Cheers
Nic

--
Dr Nic Williams
 http://www.drnicwilliams.com - Ruby/Rails blog
skype: nicwilliams
(m) +31 62 494 8552
(p) +61 7 3305 7522 (finds me anywhere in the world)
(f) +61 7 3305 7572 (sends fax to my email)

___
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

___
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core






--
Rodrigo Kochenburger
divoxx at gmail dot com
Linkedin professional profile: http://www.linkedin.com/in/rodrigok
___
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core


Re: [Rails-core] [ann] Super DRY models - Auto-associations and validations

2006-08-14 Thread David Heinemeier Hansson

I've written an ActiveRecord extension that allows Associations to be
automatically generated at runtime without requiring has_many and
belongs_to to be defined in the class. The use of has_many vs has_one is
determined by the pluralisation of the method call.


Very cool stuff, Nic. I think it would be a great app/plugin to use
against databases that follow Rails conventions but that does not
necessarily have a Rails application already.

I don't think its a good fit for core, though. Primarily because it
splinters the overview. I don't have any models in any of my real
applications where the automatically defined rules would be
sufficient. And when they're not, it means that my validates_format_of
will have to be defined explicitly while the validates_presence_of is
magic. Or that my has_many :comments, :order = created_at DESC has
to be explicit, but my has_one :author is automatic.

But again, please do keep pushing on with this. Just because its not a
good fit for core, doesn't mean it ain't cool. Rock on.
--
David Heinemeier Hansson
http://www.loudthinking.com -- Broadcasting Brain
http://www.basecamphq.com   -- Online project management
http://www.backpackit.com   -- Personal information manager
http://www.rubyonrails.com  -- Web-application framework
___
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core


Re: [Rails-core] [ann] Super DRY models - Auto-associations and validations

2006-08-14 Thread Andrew Kaspick

I would agree that this is a nice way to get started with your models,
but once you need to do anything beyond the basics, like association
extensions for example, even simply renaming the association, then
you'll have to define the association anyway.

Nice idea, but I'd rather see this remain as a plugin instead of users
getting used to the fact that you don't have to define model
associations or provide validations.

If all this did was generate the base model with the associations and
validations then that would definitely relieve some initial
development time and possibily worthy of core inclusion.

Andrew

On 8/14/06, Dr. Ernie Prabhakar [EMAIL PROTECTED] wrote:


Hi Nic,

I for one think this is incredibly cool, and would love to see it in Rails
1.2 (as part of core)...

Thanks!
-- Ernie P.

On Aug 8, 2006, at 3:33 AM, Nic Williams wrote:
I've written an ActiveRecord extension that allows Associations to be
automatically generated at runtime without requiring has_many and
belongs_to to be defined in the class. The use of has_many vs has_one is
determined by the pluralisation of the method call.

Additionally, it uses the :null = false attribute of columns to provide
validates_presence_of automatically to models too.

If any of this code is relevant for Core Rails, let me know and I'll extract
it from the gem and create a patch for core. The gem has received a good
reception on the Ruby + RoR forums.

http://drnicwilliams.com/2006/08/07/ann-dr-nics-magic-models/

Cheers
Nic

--
Dr Nic Williams
 http://www.drnicwilliams.com - Ruby/Rails blog
skype: nicwilliams
(m) +31 62 494 8552
(p) +61 7 3305 7522 (finds me anywhere in the world)
(f) +61 7 3305 7572 (sends fax to my email)
___
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

___
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core




___
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core


Re: Re: [Rails-core] [ann] Super DRY models - Auto-associations and validations

2006-08-14 Thread Kyle Maxwell

If all this did was generate the base model with the associations and
validations then that would definitely relieve some initial
development time and possibily worthy of core inclusion.


+1 for addition to script/generate model/scaffold/etc.
___
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core