Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nesting Models will cause the query to be stored incorrectly in the local variable scope #846

Closed
bawelter opened this issue Mar 7, 2018 · 4 comments
Milestone

Comments

@bawelter
Copy link

@bawelter bawelter commented Mar 7, 2018

When passing the argument for the query name, Coldfusion will store the result in a struct if given in dot notation as per it's documentation. This causes issues when organizing the models subdirectories similar to how we are able to do this with controllers. I was able to get around this by using isDefined and evaluate in place of structKeyExists and local[arguments.debugName]

<cfif StructKeyExists(local, arguments.debugName)>
	<cfset local.$wheels.rv.query = local[arguments.debugName]>
<cfelseif isDefined("local.#arguments.debugName#")>
	<cfset local.$wheels.rv.query = evaluate("local.#arguments.debugName#")>
</cfif>

The file is wheels/model/adapters/cfquery.cfm

@bawelter

This comment has been minimized.

Copy link
Author

@bawelter bawelter commented Apr 9, 2018

Created a plugin to fix the issue until this is resolved.

https://www.forgebox.io/view/cfwheels-model-nesting
https://github.com/bawelter/cfwheels-model-nesting

@neokoenig

This comment has been minimized.

Copy link
Member

@neokoenig neokoenig commented Apr 10, 2018

@perdjurner Whilst we don't technically support nested models directories, is there any reason not to implement this in 2.1? I'm always wary of evaluate(), but that might just be me.

@perdjurner

This comment has been minimized.

Copy link
Contributor

@perdjurner perdjurner commented Apr 10, 2018

Wouldn't a better fix be to make sure that arguments.debugName is a valid variable name by removing spaces and periods (.) from it?

@perdjurner perdjurner added this to the 2.0.2 milestone Apr 17, 2018
@bawelter

This comment has been minimized.

Copy link
Author

@bawelter bawelter commented Apr 19, 2018

The only reason I did the fix this way is lack of research into how debugName is being used and maximum compatibility until the optimal solution is realized. Personally I wanted to remove debug name and use a static variable name for the query result returned and then put it into the returned struct with the debug name as the key to resolve the issue.

@neokoenig neokoenig modified the milestones: 2.0.2, 2.1.0 May 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.