Code Monkey home page Code Monkey logo

Comments (6)

dbelanger avatar dbelanger commented on June 12, 2024

Reported by @blastiko on issue #1216. Most important was his discovery when using a where statement:

Update
This NOT work:
moduleclassroom=model("moduleclassroom").findByKey(select="teachers.firstname,secondteachers.firstname", key=params.key, include="teacher,secondteacher");

This NOT work:
moduleclassroom=model("moduleclassroom").findByKey(select="teachers.firstname,secondteachers.firstname AS secondteachers_firstname", key=params.key, include="teacher,secondteacher");

This NOT work:
moduleclassroom=model("moduleclassroom").findAll(select="teachers.firstname,secondteachers.firstname", where="moduleclassrooms.id = #params.key#", include="teacher,secondteacher");

This WORK:
moduleclassroom=model("moduleclassroom").findAll(select="teachers.firstname,secondteachers.firstname AS secondteachers_firstname", where="moduleclassrooms.id = #params.key#", include="teacher,secondteacher");

from cfwheels.

blastiko avatar blastiko commented on June 12, 2024

There appears to be an overwriting of table "teacher" data relative to the "secondteacher" data.
Perhaps is a alias building error?
Coused by wrong use (or not present) of AS clause in the query?

from cfwheels.

dbelanger avatar dbelanger commented on June 12, 2024

We made need an "alias" parameter on belongTo if the user wishes to join a table twice. This is a little more of @blastiko 's troubleshooting. I believe our auto-adding the table name to the select statement may be causing the issues.

@dbelanger: What happens if

  1. you only include the secondTeacher and
    
  2. you reverse the include order (ie. include= "secondTeacher, teacher")
    

@blastiko: With modelName="teachers" in module cfc

I get this error: "Error Executing Database Query. --Unknown column 'teachers.id' in 'field list'"
I get this error: "Executing Database Query. --Unknown column 'teachers.deletedat' in 'on clause'"

With modelName="teacher" in module cfc

I get this error: "Error Executing Database Query. --Unknown column 'teachers.firstname' in 'field list'"
I get this error: "Error Executing Database Query. --Unknown column 'teachers.deletedat' in 'on clause'"

If i use "teacher,secondteacher" i get no error but same initial problem

I've got those errors indipendently if i use modelName="teachers" or modelName="teacher", but only if i use include="secondtheacher,teacher". If i use include="teacher,secondtheacher" i get no errors, only wrong data for secondteacher.

from cfwheels.

mikegrogan avatar mikegrogan commented on June 12, 2024

I've definitely run into similar issues over the years and ended up just writing SQL. Glad this is being reviewed! Thanks for all the hard work.

from cfwheels.

michaeldiederich avatar michaeldiederich commented on June 12, 2024

I was trying a similar model and i noticed, that the both tables are used in the query like ...

FROM table
LEFT OUTER JOIN tablejoin ON table.first_key = tablejoin.primarykey
LEFT OUTER JOIN tablejoin AS tablejoin_ies ON table.second_key = tablejoin_ies.primarykey

So, there is a attached _ies in the join and I cannot find this in the wheels repository or somewhere else. Where in the code is this attached?

from cfwheels.

michaeldiederich avatar michaeldiederich commented on June 12, 2024

FYI: There is a function $singularizeOrPluralize() in wheels/global/internal.cfm, at line 1080 ff.

from cfwheels.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.