wash_out
wash_out copied to clipboard
Defining custom SOAP object fields for ActiveRecord models
I'm unable to change SOAP ComplexType fields for ActiveRecord models and I'm always stuck with the model's DB columns including created_at
and possibly other unwanted fields, like in this WSDL excerpt:
<xsd:complexType name="my_model">
<xsd:sequence>
<xsd:element name="id" type="xsd:int" nillable="true"/>
<xsd:element name="name" type="xsd:string" nillable="true"/>
<xsd:element name="created_at" type="xsd:dateTime" nillable="true"/>
<xsd:element name="updated_at" type="xsd:dateTime" nillable="true"/>
</xsd:sequence>
</xsd:complexType>
What I want to do is to define new fields and/or get rid of others. Obviously I tried
class MyModel < ActiveRecord::Base
map name: :string, other_field: :double
end
but it results in undefined method 'map' for #<Class:0x00000005bada60>
. Of course, making MyModel
extend from WashOut::Type
works fine but I want to keep instances of MyModel
ActiveRecord objects. Is there any way to deal with it other than writing another class (extending from WashOut::Type
) which would serve as a container around MyModel
? Am I missing a module which I can include into an ActiveRecord class?
I think you need to create a WashOut::Type
class, this is how I map mine:
class Soap::Account < WashOut::Type
map name: :string,
balance: :double,
minimum_balance: :double,
currency: :string
end
@jdsampayo as I said, creating a container-like class such as the one you proposed works fine. However I'd prefer to be able to configure an existing ActiveRecord
model rather than duplicate code by having to define separate classes for all models.