I have a small social network app and i am creating a kind of activity
stream for a user.
A user can post shouts and photos (models Shout and Photo).
These 2 models have a profile_id and place_id (where shout is posted
or photo is uploaded).
What i want to do now is get an array of these 2 models (objects) to
make an xml file like this:
<objects …>
…
…
…
…
I can retreive these models by place_id or by profile_id!
If you have a place object then the photos are accessible as
place.photos and the shouts in place.shouts. These will return arrays
of Places and Shouts.
Colin
Hey,
But this will make 2 seperate arrays or am i wrong…
i want to have place.shouts and place.photos in the same array…
so like @objects = place.photos and place.shouts (but that don’t work
off course)
and then i do @objects.to_xml
Do you really think that bumping after less than 24 hours will get
 people to help you?  (Hint: it won’t.)
It will
No it didn’t, if you notice I replied to your original not the bump.
It was just coincidence. An apology would have been a better response
than that above. It is not good to antagonise those that you hope
will help you.
If you have a place object then the photos are accessible as
place.photos and the shouts in place.shouts. These will return arrays
of Places and Shouts.
i have used include but is not a good option for me… it includes the
model (object) in the child of the xml file like this
I managed now to get an array of the shouts and photos like this @objects = [@place.shouts, @place.photos]
and i get the objects in the xml file but the xml is like this now:
-
--
..
THIS IS PHOTO
--
-
--
..
SHOUT
--
so i get first the shouts and then the photos and this again in an
array… not how i wanted… and it has to be sorted on date and not
first the photos and then the shouts…
Any idea how to solve that?
[snip]
But this will make 2 seperate arrays or am i wrong…
i want to have place.shouts and place.photos in the same array…
so like @objects = place.photos and place.shouts (but that don’t work
off course)
and then i do @objects.to_xml
How can i do this?
Is that the real question then? It was not clear to me.
What is, I don’t see any question above. Oh, you mean the one half a
mile below?
@objects = [@place.shouts, @place.photos]
  …
  SHOUT
–
so i get first the shouts and then the photos and this again in an
array… not how i wanted… and  it has to be sorted on date and not
first the photos and then the shouts…
Any idea how to solve that?
But with this i got 2 arrays and I need 1 array with all the photos
and shouts in it…
and if i do @objects = [@shouts, @photos] and then @objects.to_xml, I
get the same as a few posts above:
You can still just use one request, but you need to build your
associations better. I’m not sure exactly what you have in each and
every table but something you should consider here is not to
over-normalize your db/tables too much.
For instance, if one of those tables just contains one or two columns,
does it have to be a separate table? Or, can combine it with another
table? If you need to have separate foreign keys for specific areas of
a table, you can look at self-referential joins.
It took me a little while to realise that it is not fetching the data
that is the OPs problem but how to use to_xml to generate his xml in
the way he wants.
It took me a little while to realise that it is not fetching the data
that is the OPs problem but how to use to_xml to generate his xml in
the way he wants.
Colin
The problem is two fold:
Controller
def my_xml @shouts = Shout.find(:all, :include => [:place, :profile])
respond_to do |format|
format.html
format.xml { render :xml, :xml => @shouts.to_xml }
end
end
so in these 2 objects there is a profile_id and a place_id. I only
need to have these 2 objects combined per place or per profile (sorted
by profile_id or by place_id)!
A place has photos and shouts and a profile has photos and shouts…
I am creating an android Application and for this i need to make one
request with these 2 objects combined in 1 xml file.
I hope someone can help me, really need to find this!