Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Why is my SQL "expanded"?

I have that:
public function messagesController_beforeConversation_handler ($Sender) { $Locations = Gdn::Database()->SQL() ->Select('cl.UserID, cl.Longitude, cl.Latitude, cl.DateUpdated, cl.Body') ->From('ConversationLocation cl') ->GetSelect(); // for debugging // ->Where('ConversationID', $Sender->EventArguments['Message']->ConversationID) // ->Get() // ->ResultArray(); decho($Locations);
and get a fatal error because tables UserConversation and User are added to my SQL:
Column 'ConversationID' in where clause is ambiguous select u.UserID as `UserID`, cl.Longitude as `Longitude`, cl.Latitude as `Latitude`, cl.DateUpdated as `DateUpdated`, cl.Body as `Body`, uc.LastMessageID as `LastMessageID`, uc.CountReadMessages as `CountReadMessages`, uc.DateLastViewed as `DateLastViewed`, u.Name as `Name` from GDN_ConversationLocation cl, GDN_UserConversation uc join GDN_User u on uc.UserId = u.UserId where ConversationID = :ConversationID
I cannot see which function in /library/database
is responsible for that so that I could surpress it.
Can anyone help me out?
0
Comments
what version of vanilla?
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
The actual event is
BeforeAddConversation
the only other simular event isBeforeConversationMeta
First
Gdn::Database()->SQL()
,Gdn::SQL()
and$Sender->SQL
are equivalent in this context.If you are inject in the middle of a query being built you would expect it to end up like that.
Secondly if you have a new kind of data best do it in the context of a model with methods. Rather cluttering the the controller space with sql calls.
grep is your friend.
re: getselect
try check this->_Froms
and _FromTables
https://github.com/vanilla/vanilla/blob/2.1/library/database/class.sqldriver.php#L835
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
The current one, what else!
I want to add something to a conversation (it's funny that there are no AfterSomething events in conversations application by the way). BeforeConversation brings my output on top of a conversation.
That's good to know! I would have thought I start a new Sql query when not using $Sender->SQL
That's what I would have expected, but I've put a
Gdn::Database()->SQL()->Reset();
before my query, trieddecho(Gdn::Database()->SQL()->GetSelect()); die;
which gave me a simple "select *" and that's why I'm pretty sure, that I'm not conflicting with an existing SQL. That was my first thought when I saw that ugly error messageYes, that would be way more cleaner and I would be full of shame if anybody could see the code I'm working with! I've started with models and views mixed in the controller and in this case I've even got inline css and inline js in my "inline" view.
But I've got an excuse! I'm still testingand as soon as it is getting serious, I will be more structured!
That's where I was looking at, but I thought there is some automagical mapping when my table has a column UserID and a column ConversationID.
But maybe it is really that I'm reusing an existing SQL. Maybe I'll investigate where my Event is fired...
BeforeConversation is called in the middle of the messages controller index view, so I guess it could not have an "open" $Sender->Sql, right?
Try to keep model/sql out of view or most controller logic. Views are for presentation not for heavy logic, instead put it in Data. that is also important, becuase Data is used in other DeliveryMethods also view is far too late for getting data.
i sound like you a hook has a an implement sql call. I would check your plugins.
grep is your friend.
OH MY GOD! Please delete this question out of your memories: it really has been influenced by another plugins messing around, but that "other" plugin was the same plugin: I've tried that sql in another function call before.
Oh what a shame...
it still provided some interesting feedback. And your questions are always thought provoking and interesting.
it was elegant though
at least, I hope it was. 
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
yep views are not the place for this logic.
grep is your friend.
I'm now cleaning up the code before I do anything else with it. If it would be halloween, I would have posted it in order to scare the hell out of you