Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

Querying via Many-to-Many relationships uses bad key #11

@amedveczki

Description

@amedveczki

See this thread:
http://groups.google.com/group/datamapper/browse_thread/thread/47c04728de93b2ee

If I have 2 models (Sentence, Word), which have a Many-to-Many
relationship, and Word has a field 'word', the following query:

Sentence.all(:words => { :word => "Hello" })

Tries to match "sentences.id" to "words.id" (live example at
http://pastebin.ca/2097242 ) :

FROM "sentences" 
WHERE "id" IN 
    (SELECT "words"."id"    # Query result will be a single words.id, 
which will be used as sentence id 
     FROM "words" 
     INNER JOIN "sentence_words" ON "words"."id" = 
"sentence_words"."word_id" 
     INNER JOIN "sentences" ON "sentence_words"."sentence_id" = 
"sentences"."id" 
     WHERE "words"."word" = 'Hello') 
ORDER BY "id" 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions