[Nitro] Help creating a ObjectGraph adapter for RubyAMF
aaron smith
beingthexemplarylists at gmail.com
Tue May 22 11:11:16 EDT 2007
On 5/22/07, Jonathan Buch <john at oxyliquit.de> wrote:
> Hi,
>
> let's hope I can help you out here.
>
>
> (here be rest of Og setup and Og.start)
>
> > 1: The result class and data structure
>
> Are you sure you want the raw result class? Wouldn't some kind of Hash,
> OpenObject, Struct suffice?
>
> However, this does work with Og.
>
> SomeModel.ogmanager.with_store do |store|
> result = store.query("SELECT")
> end
>
> as the result 'data structure' however changes even between databases
> (postgresql pure ruby, postgresql extension) I would advise against
> that.
>
> # returns an array
> result = SomeModel.find() # ask if you need more help with Og queries
>
> > 2: The column names returned in the query
>
> column_names = SomeModel.serializable_attributes
>
> > 3: The row count
>
> row_count = result.size
>
> > 4: The actual returned data
>
> Are you sure you want an array here? (like in the AR example)
>
> result.inject([]) do |array,some_model|
> array << column_names.inject({}) do |hash,col|
> hash[col] = some_model.send(col)
> hash
> end
> end
>
> will produce a big array with hashes inside, adapt as necessary.
>
> I hope that helps!
>
> 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
>
Thanks!, That just about sets me up for ObjectGraph adapter. Couple
more questions:
---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.
---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.
--Thanks so much for your help.
-Aaron
More information about the Nitro-general
mailing list