option to specify a different name for an association.
Here is an exmaple:
class UserSerializer < ActiveModel::Serializer
- has_many :followed_posts, :as => :posts
- has_one :owne_account, :as => :account
+ has_many :followed_posts, :key => :posts
+ has_one :owned_account, :key => :account
end
-Using the :as without a :serializer option will use implicit detection
+Using the :key without a :serializer option will use implicit detection
to determine a serializer. In this example, you'd have to define two classes: PostSerializer
and AccountSerializer. You can also add the :serializer option
to set it explicitly:
class UserSerializer < ActiveModel::Serializer
- has_many :followed_posts, :as => :posts, :serializer => CustomPostSerializer
- has_one :owne_account, :as => :account, :serializer => PrivateAccountSerializer
+ has_many :followed_posts, :key => :posts, :serializer => CustomPostSerializer
+ has_one :owne_account, :key => :account, :serializer => PrivateAccountSerializer
end