Skip to content

Associations between ActiveResource and ActiveRecord #292

Closed

Description

@mauro-ni

Is there a way to create associations between ActiveResource models and ActiveRecord ones?
I tried to add a belongs_to association and I got the following error:

NoMethodError (undefined method `arel_table' for Project:Class)

Many thanks.
Mauro

Activity

  1. rafaelfranca commented on May 22, 2018

    @rafaelfranca
    Member

    No. There is no way to create Active Record associations between models that are not Active Record models.

  2. mauro-ni commented on Jun 25, 2018

    @mauro-ni
    Author

    @rafaelfranca I can easily define methods on local resources in order to be able to load remote ones, but then I have N+1 query problems when working with collections.

    Example: a collection of local resources (AR), each one belonging to a remote one (ARes)
    How would you avoid this?

    Many thanks,
    Mauro

  3. basicBrogrammer commented on Jun 6, 2023

    @basicBrogrammer

    I created a PR that demonstrated a potential implementation for a belongs_to_resource relationship. This could also be pulled out into a stand alone gem or left as a module that does not patch ActiveRecord upon initialization. #393

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions