Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Active Record] Add belongs_to_resource to active record #393

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

basicBrogrammer
Copy link

Pull Request Description

This pull request adds the belongs_to_resource class method to the ActiveResource Ruby on Rails gem. This method allows for the association of an ActiveResource with an ActiveRecord.

Changes Made

The belongs_to_resource method has been added to the ActiveResource::Base
class. This method takes two arguments: the name of the association and
class_name keyword argument. The options hash can include the class_name
option to specify the name of the ActiveResource class to associate with.

Example Usage

class Person < ActiveResource::Base
  self.site = "http://api.people.com:3000"
end

class Address < ActiveRecord::Base
  belongs_to_resource :person
end

With this association, an Address active record model can be associated with a Person active resource via the person_id foreign key. The Person object can be accessed through the person method on the Address object.

Testing

Unit tests have been added to ensure that the belongs_to_resource method works as expected. These tests cover the basic functionality of the method, as well as the use of the class_name.

Related Issue

This pull request is related to #292.

@basicBrogrammer basicBrogrammer force-pushed the add_belongs_to_resource_active_record_patch branch 5 times, most recently from 43264c0 to 76d1569 Compare June 5, 2023 16:12
@basicBrogrammer basicBrogrammer marked this pull request as ready for review June 6, 2023 19:48
lib/active_resource/railtie.rb Outdated Show resolved Hide resolved
lib/active_resource/railtie.rb Show resolved Hide resolved
lib/active_resource/associations/active_record.rb Outdated Show resolved Hide resolved
lib/active_resource/railtie.rb Outdated Show resolved Hide resolved
@basicBrogrammer basicBrogrammer force-pushed the add_belongs_to_resource_active_record_patch branch from 76d1569 to c57ce29 Compare June 7, 2023 12:54
@basicBrogrammer basicBrogrammer force-pushed the add_belongs_to_resource_active_record_patch branch from c57ce29 to 681f948 Compare June 7, 2023 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants