[Feature] ActiveResource - Associations through reflections #230

Closed
wants to merge 4 commits into
from

Conversation

Projects
None yet

SweeD commented Mar 17, 2011

Matthias Folz and I've added associations (has_many and has_one) via reflection classes to ActiveResources.

Here is the link to the googlegroups discussion:
http://groups.google.com/group/rubyonrails-core/browse_thread/thread/dd8d83955a7cf9e8/1f95a896887cd9a9#1f95a896887cd9a9

And the lighthouse ticket:
https://rails.lighthouseapp.com/projects/8994/tickets/6473-activeresource-adding-associations-through-reflections#ticket-6473-1

I hope, it's not impolite to open a pull request without an answer on the lighthouse ticket form a core member.
If it's so: I'm sorry... ;)

Greetz
Markus Schwed

SweeD commented Apr 26, 2011

This ticket would be the begin of extending active resource with more restful features.
(like association link resolving as seen in Atomic-feeds)

Contributor

miloops commented Apr 27, 2011

What about belongs_to? If we add has_many and has_one is intuitive to have belongs_to associations, right?

SweeD commented Apr 27, 2011

Hi miloops,

in the first step, we've added just has_one and has_many associations to configurate the :class_name (more options will follow), which should be used for the initialization of associated objects.
(more detailed description in the linked Lighthouse ticket)

So, before it get merged, we should add a belongs_to association, that adds an accessor for the parent, which it belongs to?

Should we also add some autoresolving for a belongs_to association, if the request response (for i.e. Comment.find(2) ) only includes the 'post_id' instead of all attributes (nested) for the 'post' object. ?

@SweeD SweeD closed this Apr 27, 2011

@SweeD SweeD reopened this Apr 27, 2011

SweeD commented Apr 27, 2011

Sorry... i closed the pull request by mistake... :)

Contributor

smartinez87 commented May 2, 2011

Please remember to include the guides updated with this change, to make it a complete request.

SweeD commented May 5, 2011

I just rebased to the latest rails master, so the least added commits aren't new commits.

activeresource/lib/active_resource/associations.rb
+ # ====
+ #
+ # <tt>has_many :comments, :class_name => 'myblog/comment'</tt>
+ # Would resolve this comments into the <tt>Myblog::Comment</tt> class.
@gogolok

gogolok May 8, 2011

this -> those

activeresource/lib/active_resource/reflection.rb
+ #
+ # Associations in ActiveResource would be used to resolve nested attributes
+ # in a response with correct classes.
+ # Now they could be specify over Associations with the options :class_name
@gogolok

gogolok May 8, 2011

specify -> specified

Owner

guilleiguaran commented Jun 1, 2011

@SweeD: Do you finish belongs_to?

@core members: is there any chance you can review this for inclusion in Rails 3.2?

SweeD commented Jun 4, 2011

Sorry, I was on vacation.

We will finish it within the next two weeks.

Greetz
SweeD

Member

sikachu commented Jun 15, 2011

You have two more days to complete your patch :P (haha, just j/k)

I'll come back and check again after you've finished it. If you can finish belongs_to, and squash some of the tiny commits that would be great. :)

@ghost ghost assigned sikachu Jun 15, 2011

Owner

guilleiguaran commented Jun 15, 2011

Just a friendly reminder, I keep an eye on this too, hahaha :D

SweeD commented Jun 22, 2011

@sikachu @guilleiguaran
Woohoo... haven't forgot.... We'll finish it.
Little bit stressful these days... :D

Please don't stone me... xD

Owner

guilleiguaran commented Jul 8, 2011

Looks like this is finished, I see belongs_to added on the code, I will start to test this now :)

@SweeD: great work!!!

SweeD commented Jul 9, 2011

Sorry, it's not finished, already.
But almost... ;)

Have to write the resolving of the parent for a belongs_to association and squash the tiny commits... :)
Will finish these days!

activeresource/lib/active_resource/associations/builder/association.rb
+module ActiveResource::Associations::Builder
+ class Association #:nodoc:
+
+ # providing a Class-Variable, which will have a differend store of subclasses
@dasch

dasch Jul 9, 2011

Contributor

"differend" -> "different"

+ autoload :HasMany, 'active_resource/associations/builder/has_many'
+ autoload :HasOne, 'active_resource/associations/builder/has_one'
+ autoload :BelongsTo, 'active_resource/associations/builder/belongs_to'
+ end
@dasch

dasch Jul 9, 2011

Contributor

Try to use autoload_at here, i.e.

module Builder
  autoload_at 'active_resource/associations/builder' do
    autoload :Association
    autoload :HasMany
    autoload :HasOne
    autoload :BelongsTo
  end
end
Owner

jeremy commented Oct 9, 2011

Good idea and nice implementation. Targeting Rails 3.2.

+1 this is awesome.

Member

sikachu commented Nov 29, 2011

@SweeD what's the progress of this patch? I want to make sure this can be merged into Rails 3.2 ;)

Owner

guilleiguaran commented Nov 30, 2011

+1, this should be in master soon :)

SweeD commented Dec 2, 2011

Oha, haven't got time for a while.

Will finish it this month, sorry about that. ;)

SweeD commented Dec 2, 2011

@sikachu we "just" have to finish the belongs_to association and then, we're done.

Owner

jeremy commented Dec 14, 2011

Have to write the resolving of the parent for a belongs_to association and squash the tiny commits...

Rails 3.2 release candidate is coming within days, so this is going to miss the boat without a final push!

Member

sikachu commented Dec 14, 2011

true!

SweeD commented Dec 15, 2011

We will work on it today and hopefully finish it tomorrow.

Noting that the last comment is from Dec 15th with a hopeful finish by Dec 16th. Just wanted to bump this to see if the status has changed.

SweeD commented Feb 8, 2012

Sorry
..but sadly, the status haven't changed since 15.12.

But we will finish it 100% this weekend.

SweeD commented Feb 12, 2012

@sikachu ....and finally: Done! :D

Really, really sorry for the delay.
Looking forward to feedback... :)

Owner

jeremy commented Mar 3, 2012

@SweeD great!

SweeD commented Mar 5, 2012

@jeremy Thanks!

Something to change/cleanup or so?

SweeD commented Mar 14, 2012

Closed for new pull request in new rails/activeresource repo.

rails/activeresource#1

Oh... it's the first one... xD

@SweeD SweeD closed this Mar 14, 2012

@SweeD SweeD referenced this pull request in rails/activeresource Oct 18, 2013

Merged

[Feature] ActiveResource - Associations through reflections #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment