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

Calling operator + on ActiveRecord::Relation force loading all rows from database and doesn't return a new Relation object #12

Closed
kmatrah opened this issue Jul 5, 2011 · 1 comment

Comments

@kmatrah
Copy link

kmatrah commented Jul 5, 2011

In ActiveRecord::FriendModel, in the instance methods, calling operator + on 2 relations force loading all rows from database to merge the 2 relations.

Exemple: lib / amistad / active_record / friend_model.rb line 68-70:
def friends
self.invited(true) + self.invited_by(true)
end

The friends method returns an Array instead of an ActiveRecord::Relation object and it's not possible anymore to chain any ActiveRecord query method like offset, limit and order.

Is it possible to update the gem and use the method merge from ActiveRecord::SpawnMethods to merge the two Relation objects and get a new one ?

def friends
self.invited(true).merge self.invited_by(true)
end

@raw1z
Copy link
Owner

raw1z commented Jul 5, 2011

I am working on it. Thank you for your suggestion.

Le 5 juil. 2011 à 12:10, kmatrah a écrit :

In ActiveRecord::FriendModel, in the instance methods, calling operator + on 2 relations force loading all rows from database to merge the 2 relations.

Exemple: lib / amistad / active_record / friend_model.rb line 68-70:
def friends
self.invited(true) + self.invited_by(true)
end

The friends method returns an Array instead of an ActiveRecord::Relation object and it's not possible anymore to chain any ActiveRecord query method like offset, limit and order.

Is it possible to update the gem and use the method merge from ActiveRecord::SpawnMethods to merge the two Relation objects and get a new one ?

def friends
self.invited(true).merge self.invited_by(true)
end

Reply to this email directly or view it on GitHub:
#12

@raw1z raw1z closed this as completed Mar 6, 2012
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

No branches or pull requests

2 participants