Acts as automatic has two purposes:
1) provide acts_as_automatic act, which will automatically run the
appropriate methods when conventions are adhered to (e.g. if you have
category_id, it will assume that the model belongs_to :category). Only
belongs_to via something_id is currently implemented.
2) Allow the creation of associations.yml, which will hold associations
instead of inside each individual model. There''s no need for a custom
acts--the extension will automatically do its work if acts_as_automatic
is installed and it finds associations.yml.
It will automatically add belongs_to to a model if it finds has_many or
has_one pointing to that model, and it supports acts_as_list.
I will probably refactor the code to automatically support any
"macros",
because there are essentially only three types of macros:
macro_name
macro_name :symbol, Hash
macro_name Hash
I will assume that each key represents a macro, and check whether
there''s nil underneath it, a Hash underneath it, or a Hash pointing to
a
Hash underneath it.
Example associations.yml:
has_many:
category : articles
author : articles
article : tags
author : {tags: {through: articles}}
has_one:
article : attachment
acts_as_list:
article : {scope: category}
author :
Incidentally, the syntax for macro_name :symbol, Hash could have been:
author : [tags, {through: atricles}]
and I may convert to that when I refactor the code.
-- Yehuda Katz
--
Posted via http://www.ruby-forum.com/.
Acts as automatic has two purposes:
1) provide acts_as_automatic act, which will automatically run the
appropriate methods when conventions are adhered to (e.g. if you have
category_id, it will assume that the model belongs_to :category). Only
belongs_to via something_id is currently implemented.
2) Allow the creation of associations.yml, which will hold associations
instead of inside each individual model. There''s no need for a custom
acts--the extension will automatically do its work if acts_as_automatic
is installed and it finds associations.yml.
It will automatically add belongs_to to a model if it finds has_many or
has_one pointing to that model, and it supports acts_as_list.
The code is available via svn at
http://svn.visualjquery.com/admin_console/trunk/admin_console/vendor/plugins/acts_as_automatic/
I will probably refactor the code to automatically support any
"macros",
because there are essentially only three types of macros:
macro_name
macro_name :symbol, Hash
macro_name Hash
I will assume that each key represents a macro, and check whether
there''s nil underneath it, a Hash underneath it, or a Hash pointing to
a
Hash underneath it.
Example associations.yml:
has_many:
category : articles
author : articles
article : tags
author : {tags: {through: articles}}
has_one:
article : attachment
acts_as_list:
article : {scope: category}
author :
Incidentally, the syntax for macro_name :symbol, Hash could have been:
author : [tags, {through: atricles}]
and I may convert to that when I refactor the code.
-- Yehuda Katz
--
Posted via http://www.ruby-forum.com/.