Relate model to self

So I have a table setup (I’m not wed to it) that looks like:

words


id

name

etc…

words_synonyms


word_id

syn_id

Words can have synonyms that all point back to the “root” word, and what I’d like to be able to do is to get the root word for a given word, and second find all synonyms for a given word.

Is there a relation I can setup that allows this?

So far I’ve tried:

‘root’=>array(self::BELONGS_TO, ‘Word’, ‘words(syn_id,word_id)’),

‘synonyms’=>array(self::HAS_MANY,‘Word’,‘words_synonyms_data(word_id,syn_id)’),

But I’ve had no luck. What setup can/should I be using to accomplish this?

words


id

name

etc…

Try to this:

words


id=0

name=root

etc…

How about something like this?

Table:

id

root_id

synonym_id

name

etc…


'root'=>array(self::BELONGS_TO, 'Word', 'root_id'),

'synonyms'=>array(self::HAS_MANY,'Word','synonym_id'),

I guess that would work better, thanks!