# ActiveRecord model classes not allowed in :expects

**URL:** <https://www.ruby-forum.com/t/activerecord-model-classes-not-allowed-in-expects/90748>\
**Category:** Rails\
**Created:** [January 5, 2006, 6:26pm UTC](https://www.ruby-forum.com/t/activerecord-model-classes-not-allowed-in-expects/90748 "2006-01-05T18:26:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samwise23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@samwise23](https://www.ruby-forum.com/u/samwise23)\
**Post date:** [January 5, 2006, 6:26pm UTC](https://www.ruby-forum.com/t/activerecord-model-classes-not-allowed-in-expects/90748/1 "2006-01-05T18:26:05Z")

</div>

Hi,

I have a strange problem while using WebService API which expects an  
ActiveRecord derivate.

This is the code of the API …

* * *

## class HarvesterApi \< ActionWebService::API::Base api\_method :send\_measurand, :expects =\> [{:measurand =\> Measurand}, {:eaiSystemName =\> :string}] end

… and this of my Model

* * *

class Measurand \< ActiveRecord::Base

belongs\_to :eai\_system  
belongs\_to :measurement\_error  
acts\_as\_tree :order =\> “genId”

# Constants for validation of measurand scope

CLASSIFICATION\_BEAN = “Bean”  
CLASSIFICATION\_APPLICATION = “Application”  
CLASSIFICATION\_WORKFLOW = “Workflow”

# Validation part

validates\_presence\_of :name, :genId, :classification

validates\_uniqueness\_of :genId,  
:message =\> “The GenID must be unique”

validates\_inclusion\_of :classification,  
:in =\> [ CLASSIFICATION\_BEAN,  
CLASSIFICATION\_APPLICATION, CLASSIFICATION\_WORKFLOW ],  
:message =\> “Classification must be of  
the following: #{CLASSIFICATION\_BEAN}, #{CLASSIFICATION\_APPLICATION},  
#{CLASSIFICATION\_WORKFLOW}”

## end

When I invoke the service.wsdl URL I’m getting the error from the Topic  
(Complete Error page follows):

* * *

## ActiveRecord model classes not allowed in :expects

How can that be? Did I any mistakes? That would be no suprise, bacause  
I’m new to Rails and Ruby. But as I understand it, it is possible to use  
a AR as structured type in the method signature of a WebService.

Thanks for your help.

Dirk

---

<div class="post-metadata">

**Author:** ![samwise23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@samwise23](https://www.ruby-forum.com/u/samwise23)\
**Post date:** [January 5, 2006, 6:40pm UTC](https://www.ruby-forum.com/t/activerecord-model-classes-not-allowed-in-expects/90748/2 "2006-01-05T18:40:45Z")

</div>

By the way another WebService related question:

I want to give the Model class that should be send over the wire an  
Array which can holds the children of that Model (The model has a tree  
like structure). Is this possible? I found nothing about this topic  
neither in the Agile Rails Book nor somewhere else.

Thanks again

Dirk

---

<div class="post-metadata">

**Author:** ![samwise23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@samwise23](https://www.ruby-forum.com/u/samwise23)\
**Post date:** [January 14, 2006, 12:28am UTC](https://www.ruby-forum.com/t/activerecord-model-classes-not-allowed-in-expects/90748/3 "2006-01-14T00:28:35Z")

</div>

Dirk Breuer wrote:

> Hi,
> 
> I have a strange problem while using WebService API which expects an  
> ActiveRecord derivate.
> 
> This is the code of the API …

…snip…

> When I invoke the service.wsdl URL I’m getting the error from the Topic  
> (Complete Error page follows):

…snip…

I am seeing the same thing with Rails 1.0. I did a google search and  
found this diff:

[http://dev.rubyonrails.org/changeset/815?format=diff](http://dev.rubyonrails.org/changeset/815?format=diff)

Basically, I think they now turn it off by default due to the possible  
security issues associated with anyone being able to serialize an  
ActiveRecord class and (possibly) blindly saving it. It appears that  
they may have a flag that can be set to allow this to occur. But,  
according to the Rails book, there is a class called  
ActiveWebService::Struct that can be used in its place as an expects  
parameter to achieve the same thing and offer more security (page 427).  
I’m trying to determine how I want my SOAP service to look, so I may  
either 1) pass the fields as native types and construct the ActiveRecord  
instance on the AWS controller or 2) use a Struct subclass.

Seems like a good RoR generator could be written to write the struct  
from a given AR model to keep them in sync and allow the Struct to be a  
more of a ‘value object’. Something to consider at least…

---

<div class="post-metadata">

**Author:** ![samwise23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@samwise23](https://www.ruby-forum.com/u/samwise23)\
**Post date:** [January 26, 2006, 11:45pm UTC](https://www.ruby-forum.com/t/activerecord-model-classes-not-allowed-in-expects/90748/4 "2006-01-26T23:45:50Z")

</div>

> [http://dev.rubyonrails.org/changeset/815?format=diff](http://dev.rubyonrails.org/changeset/815?format=diff)  
> Basically, I think they now turn it off by default

Even when you set

class\_inheritable\_option :allow\_active\_record\_expects, true

it fails for me with

Internal protocol error: You have a nil object when you didn’t expect  
it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.include?  
Backtrace:  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/base.rb:1401:in  
`respond\_to?’  
…

I’m not too worried about the security concerns they mention, I still  
have to create a struct with the same parameters as the object. Maybe  
I’m missing something about the serializition. But, this runs in a  
“trusted enivorment”.

> Seems like a good RoR generator could be written to write the struct  
> from a given AR model to keep them in sync and allow the Struct to be a  
> more of a ‘value object’. Something to consider at least…

This would be ok with me. I don’t like having to hand create a struct  
for my classes.

And finally, if anyone has a :expects passing in a active\_record object  
please explain how they’re doing it. I wasted a whole day messing with  
this.

Thanks,  
Russ  
removed\_email\_address@domain.invalid
