[Solar-talk] new model & a many to many question

Rodrigo Moraes rodrigo.moraes at gmail.com
Wed Mar 14 20:06:05 PDT 2007


On 3/14/07, Paul M Jones wrote:
> The idea is that you need to specify the mapping model
> (game2platform) as a has_many relationship, and then specify the many-
> to-many as a "has_many through" the mapping relationship.  The model
> will look at the "through" relationship and generate the correct LEFT
> JOIN for you.
>
> Does that help at all?

Yes, a lot. Perfect. I made a list of the options available for
relationships and would ask about the through family soon. :)

This is what I got working, including ordering the related model:

game
    has_many games2platforms
        foreign_model games2platforms
        foreign_col game_id
    has_many platforms
        foreign_model platform
        foreign_col id
        through games2platforms
        through_foreign_col platform_id

games2platforms
    belongs_to game
        foreign_model game
        foreign_col game_id
    belongs_to platform
        foreign_model platform
        foreign_col platform_id

platform
    has_many games2platforms
        foreign_model games2platforms
        foreign_col platform_id
    has_many games
        foreign_model game
        foreign_col id
        through games2platforms
        through_foreign_col game_id

Notice that I had to define through_foreign_col and foreign_col in
game (has_many platforms) and platform (has_many games). I hope these
are expected. :)

thanks a lot,
I'll continue exploring now.

rodrigo


More information about the solar-talk mailing list