Hi all,
I had the idea of add associations to Active Resource, something like AR
associations, but only the 3 basics, belongs_to, has_one and has_many:
class Project < ActiveResource::Base
belongs_to :portfolio
has_one :project_manager
has_many :milestones
end
#--------------------------------------------------------------------
# belogns_to
p = Proyect.new
- p.portfolio
- p.portfolio=(p)
#--------------------------------------------------------------------
# has_one
p = Proyect.new
- p.project_manager
- p.project_manager=(pm)
- p.build_p.project_manager(attributes={})
- p.create_project_manager(attributes={})
#--------------------------------------------------------------------
# has_many
Project#milestones.empty?, Project#milestones.size, Project#milestones,
Project#milestones<<(milestone), Project#milestones.delete(milestone),
Project#milestones.find(milestone_id), Project#milestones.find(:all, options),
Project#milestones.build, Project#milestones.create
The way to create those new association methods could be adding a private
instance variable related to the resource, and add an instance method by
metaprogramming making the method name based on the resource name, so:
IMO this basic 3 associacionts is a good start, i did something like that in
a project that I''m working and works fine, this feature will avoid
reptition
of creates all methods by hand like this:
def project_manager
ProjectManager.find(find(:params => { :project_id => id })
end
for every model that you need to "associate".
Regards.
--
"Premature optimization is the root of all evil (or at least most of it) in
programming."
(Donald Knuth)
+-------------------------------------+
Gastón Ramos
http://gastonramos.com.ar/
GNU/Linux Counter user #450312
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.
I pushed the first working version of associations to my fork, I''ll be waiting for some feedback http://github.com/gramos/rails/blob/ares-associations/activeresource/lib/active_resource/associations.rb http://github.com/gramos/rails/blob/ares-associations/activeresource/test/cases/associations_test.rb Thanks. +-------------------------------------+ Gastón Ramos http://gastonramos.com.ar/ GNU/Linux Counter user #450312 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
I noticed that the pull request (https://github.com/rails/rails/pull/70) was closed, but I see no discussion about whether it rejected or applied and if so by whom and why. Can anyone shed light on this? John-Mason Shackelford Release Engineering Pearson 2510 North Dodge St. Iowa City, IA 52245 ph. 319-354-9200x6214 john-mason.shackelford@pearson.com http://pearsonschool.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
El Mon, 13 de Dec de 2010, a las 08:41:43AM -0800, John-Mason Shackelford dijo:> I noticed that the pull request > (https://github.com/rails/rails/pull/70) was closed, but I see no > discussion about whether it rejected or applied and if so by whom and > why. Can anyone shed light on this?Hi, I remember that the Rails Core gave me this answer: "do it as a plugin and if it works and people like, we merge it in" and that''s all that I know about it. I don''t know if there are more interested people on this feature.> > > > John-Mason Shackelford > > > Release Engineering > Pearson > > > 2510 North Dodge St. > Iowa City, IA 52245 > ph. 319-354-9200x6214 > john-mason.shackelford@pearson.com > http://pearsonschool.com > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. >-- "Optimism is an occupational hazard of programming; feedback is the treatment." (Kent Beck) +-------------------------------------+ Gastón Ramos http://gastonramos.com.ar/ GNU/Linux Counter user #450312 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.