Skip to content

support reference id which is not id for many-to-many association #56

@sio4

Description

@sio4

Hello, how about make many-to-many more flexible by support some more customizing tags?

return fmt.Sprintf("id in (%s)", subQuery), []interface{}{modelIDValue}

I have some tables for example stores and table consumers, which is related each others as many to many. But in some reason, consumers has field card_id and mapping table for this relationship should be connected by table cards_stores or transactions, using card_id and store_id.
In this case, if I can override keys id to card_id and/or consumer_id to card_id, it is possible that I make relationship between this two models directly. (without make model card and two step relationships)

for example,

SELECT name FROM stores WHERE id IN (
    SELECT store_id FROM cards_stores WHERE card_id = "0000-0000-0000-0000"
)

If I can override modelColumnID like columnFieldID, or

SELECT name FROM consumers WHERE card_id IN (
    SELECT card_id FROM cards_stores WHERE store_id = "000-00-000000"
)

If I can override id in the code reference above.

How do you think about this idea? If you feel good, I will try to make a PR for it.

For the more, In my opinion, we can consider about custom raw query per the relationship. It will be helpful for more cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    f: associationsthe associations feature in popproposalA suggestion for a change, feature, enhancement, etc

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions