jonathangeiger / kohana-jelly

See the link below for the most up-to-date code
https://github.com/creatoro/jelly
MIT License
146 stars 34 forks source link

Field factories - alternative model declaration syntax #105

Closed jerfowler closed 14 years ago

jerfowler commented 14 years ago

I see that Jelly borrows heavily from the sprig Model declaration syntax. I use a modified version of Sprig that uses Field factories and I think it would be a great inclusion for Jelly here as well.

Reasons:

  1. Cleaner looking code, may be a personal preference
  2. Displays nicer in most IDEs as the parameter values are usually a different color and pop out more so its easier to see what the field types are
  3. Most classes in Kohana 3 are factories or singletons, why break from convention in models?

Example: class Model_Post extends Jelly_Model { public static function initialize(Jelly_Meta $meta) { $meta->table('posts') ->fields(array( 'id' => Jelly::Field('Primary'), 'name' => Jelly::Field('String'), 'body' => Jelly::Field('Text'), 'status' => Jelly::Field('Enum', array( 'choices' => array('draft', 'review', 'published'))), 'author' => Jelly::Field('BelongsTo'), 'tags' => Jelly::Field('ManyToMany'), )); } }

jonathangeiger commented 14 years ago

Closed by 493cc56fbe198237625128b5aa16f413125acfd2. Thanks a lot for your help!

Now I have to go back and update all of the documentation!