Problem with returning nested json with condition

I am having 3 models

Word, WordPartOfSpeech, WordSentence

Word has many WordPartOfSpeech
WordPartOfSpeech has many WordSentence

Now with the below mentioned code i am getting the nested json as i want

@words = Word.where(“ != ?”, params[:word_id])

respond_to do |format|

format.json { render :json => @words.as_json(:include =>
{:word_part_of_speeches => {:include => :word_sentences}}) }


But the problem is i want only those word part of speeches to be
in this json which have atleast 1 approved sentence and only those
that are approved

Now if i use joins the json returned is not nested and if i use include
then condition does not work