Right now I am trying to call my model, and spit out its results into json/xml format. My only problem is, my database associations aren't being loaded or queried.
Normally, I can just run this
@campaign = Campaign.find(:all)Then get the number of hits by calling,
@campaign[0].hits
through the has_many :hits
.
But if you debug the output, it only calls the columns on the table. How would you go about having it put it alongside your query?In example:
<campaign> <category>website</category> <created-at type="timestamp">2009-01-24 14:49:02 -0800</created-at> <end-at type="date">2009-01-24</end-at> <id type="integer">14</id> <is-watched type="integer">1</is-watched> <name>Lets</name> <slug>c5334415da5c89384e42ce6d72609dda</slug> <start-at type="date">2009-01-24</start-at> <user-id type="integer">5</user-id> </campaign>
Then having it instead add another column, but witht he number of hits.
<campaign> <category>website</category> <created-at type="timestamp">2009-01-24 14:49:02 -0800</created-at> <end-at type="date">2009-01-24</end-at> <id type="integer">14</id> <is-watched type="integer">1</is-watched> <name>Lets</name> <slug>c5334415da5c89384e42ce6d72609dda</slug> <start-at type="date">2009-01-24</start-at> <user-id type="integer">5</user-id> <hits type="integer">123412</hits> </campaign>