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

Defining custom SOAP object fields for ActiveRecord models #237

Open
xlts opened this issue May 14, 2017 · 2 comments
Open

Defining custom SOAP object fields for ActiveRecord models #237

xlts opened this issue May 14, 2017 · 2 comments

Comments

@xlts
Copy link

xlts commented May 14, 2017

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?

@jdsampayo
Copy link
Contributor

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

@xlts
Copy link
Author

xlts commented May 25, 2017

@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.

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