I have one model based on ActiveRecord and another based on a Mogoid::Document. Is that possible to do an association together ?
For Example, the 2 models :
class User < ActiveRecord::Base
has_one :avatar, :dependent => :destroy
end
class Avatar
include Mongoid::Document
field :file_name
end
And retrieve User's avatar like this :
@user.avatar.file_name
Thanks !
You won't be able to use ActiveRecord relations.
You still can link the two objects using instance methods like this :
class User < ActiveRecord::Base
def avatar
Avatar.where(:user_id => self.id).first
end
def avatar=(avatar)
avatar.update_attributes(:user_id => self.id)
end
end
It would be interesting to encapsulate this in a module :)...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With