Any CFWheels users on this thread? I could use som...
# cfml-general
t
Any CFWheels users on this thread? I could use some help with datasource overrides. Not getting it to work in my case.
a
The CFWheels community decided to leave this slack channel, I'm afraid.
t
Where did they go?
a
t
Yea I've posted there before but you wait multiple days sometimes to get a response.
Ok thanks
a
Well you have to understand it's technology in the twilight of its relevance (whether they like to admit it or not), in a very small community. So... not many ppl using it.
I answer stuff I know the answers to, but - to be frank - it's not a good use of my time researching CFWheels stuff I don't already know about. Soz.
t
Understood. I don't have a choice here as the code I inherited was already in wheels and management isn't desiring a change to a new FW.
a
(I am in same position, except we're migrating away from CFML altogether)
t
I'm just trying to get the dataSource() override to work but for me it's not, yet I have a new workmate who got it working for a non-login page. I put that function call for the new DSN in the config of the "user" model but first line I reference it, it will dump the DSN as the old one, not the new. users = model("user").new(); Error says "users" table does not exist, which it doesn't in the old db but in the new db it does.
Since he got it to work on his page, it at least verifies it works, but for some odd reason not for my page. Guess I'll just have to use the old db to login and move on.
a
Ask the Q on the github forums there. What few there are do try to help.
I've never needed to mess around with DSN settings, so dunno I'm afraid.
t
Thanks Adam. Just curious, what are you switching to from CFML?
a
Just PHP. Not at all glamorous 😉
t
I feel for you.
a
I've used PHP a lot. It gets the job done. Easier to use & better thought-out than CFML, easier to find personnel that know what they're doing. Way fewer issues that don't have answers already. I'm pragmatic about effectiveness over perceived "coolness"
t
Glad you like it. I haven't touched PHP for probably 20 yrs so you very likely are spot on and it makes sense.
I just wouldn't go there at this point in my career.
Actually it was more like 30 yrs ago.
a
Oh PHP 20yrs ago was shite 😉 This is where most CFMLers formed their opinion of it. It's come a long way. I was fortunate to get the option to cross train on the job a coupla jobs ago.
Actually it was more like 30 yrs ago.
Time flies eh? Ha
t
LOL
I feel the same about CFML, with cfscript fully implemented, I enjoy it a lot.
a
Yeah same. That still has its historical baggage, but they've done good work on it in the last few releases. I'm glad writing business logic in tags is becoming a legacy concept (almost all our code is... business logic in tags, that said).
I write code in modern CFML and look at it and go "yeah, that looks nice actually. Cool".
👍🏻 1
t
Ugh I didn't like using cftags.
components is much preferred.
a
Yeah fortunately right from my first CFML job back in 2001, we "got" the distinction between business logic and view logic, and did what we could to keep tag code in views; and tucked away in tab-based CFCs when it was stuff like
<cfquery>
or
<cfldap>
etc.
(didn't stop me writing some horrific code back then though. Blimey)
n
Copy code
I'm just trying to get the dataSource() override to work but for me it's not, yet I have a new workmate who got it working for a non-login page. I put that function call for the new DSN in the config of the "user" model but first line I reference it, it will dump the DSN as the old one, not the new.
the
config()
function is cached. so you'd need to restart the app for anything in config() to get changed. i.e I don't think you can make the datasource() for an individual model dynamic per se.
⭐ 1
t
Actually in 2.x you are supposed to be able to do it, per docs here: https://guides.cfwheels.org/2.5.0/database-interaction-through-models/using-multiple-data-sources
But it does have the caveat that it doesn't work for Associations. But in my case I'm not
n
Right, but that will only get evaluated once on application start.
t
It is supposed to work on a model by model
@neokoenig Ohhh, hence it doesn't work on the login page!
n
boom.
t
lol wow!
That should be added to the docs!!
n
It is somewhere. in fact we even changed the default behavior ages (years) ago. it used to be in 1.x that development mode that config() [ then, init() ] wouldn't cache the class (you know, for easy development lol). Then everyone got confused, as it wouldn't mirror the behaviour in production. Thus, the default change so all modes cached config(). You can actually turn that off if you know the setting, but I wouldn't recommend it. Technically only the function definition is cached, not the result, which is why filters() work. but I wouldn't try to dynamically re-assign
datasource(someotherFunctionWhichReturnsDatasource())
- that way pain probably lies 🙂
t
Ok thanks Tom!
@neokoenig I upgraded wheels directory to 2.5.1 (from 2.5.0) and after login I created a new page to list the projects. In the project model config I added the datasource() for my new DSN and in the index action, the DSN is still coming up as the default, not the new override DSN.
n
@teaman I've responded on gitHub with a possible idea.
t
Thanks, Tom! I'll take a look.