[Nitro] Help creating a ObjectGraph adapter for RubyAMF
aaron smith
beingthexemplarylists at gmail.com
Wed May 23 19:05:36 EDT 2007
On 5/22/07, aaron smith <beingthexemplarylists at gmail.com> wrote:
> On 5/22/07, Jonathan Buch <john at oxyliquit.de> wrote:
> > Hi,
> >
> > > ---For this line:
> > > result = SomeModel.find() # ask if you need more help with Og queries"
> > > ---Does object graph work the same way active record does? If there is
> > > one result it is a object ObjectGraph::Result. And if it is multiple
> > > rows it is an Array of ObjectGraph::Result. If not and it always
> > > returns an array, do any of the items in the array have a special
> > > class name (IE: result[0] -> ObjectGraph::Something?). That is how I
> > > am finding out that this "result" is an ObjectGraph result.
> >
> > # Will always return an array if there are results, nil if there is no
> > # result. Array contents are always .kind_of?(Og::Model)
> > result = SomeModel.find()
> >
> > # will return return a .kind_of?(Og::Model) or nil if nothing found
> > result = SomeModel.find_one()
> >
> > So yes, you can rely on result[0].kind_of?(Og::Model) if somethings has
> > been found.
> >
> > > ---For column names.
> > > Is there anyway I can get the column names off of the "result" object,
> > > not the "SomeModel" class. As when a result is returned to me I don't
> > > know about the models, just the resulting object.
> >
> > Ah of course. :P As you can get the class from the object. :)
> >
> > if result[0].kind_of?(Og::Model)
> > result[0].class.serializable_attributes
> > end
> >
> >
> > Jo
> >
> > --
> > Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
> > _______________________________________________
> > Nitro-general mailing list
> > Nitro-general at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/nitro-general
> >
>
> Sweet! That is everything I need!
>
> #duh, i had that in the active record example.. Thanks!
> if result[0].kind_of?(Og::Model)
> result[0].class.serializable_attributes
>
> Thanks a lot!
> end
>
Hey Jo,
Is there an easier way of doing this:
result.inject([]) do |array,some_model|
array << column_names.inject({}) do |hash,col|
hash[col] = some_model.send(col)
hash
end
end
Just seems like a lot of work. Also If I do have to do it that way,
where does the some_model variable come from?
thanks
Aaron
More information about the Nitro-general
mailing list