Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 355 Vote(s) - 3.59 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String concatenation in ActiveRecord in Yii Framework?

#1
Is it possible to CONCAT values of two table columns using the Yii's ActiveRecord methods and patterns?

If is, how?

I'm currently using this:

return $this->findByAttributes(array('alias' => $alias));

But in this I need to return the concated string/values.

Please help.
Reply

#2
If you are looking for something like that:

select username||'@'||domain from user_mail_table;

to receive concatenated values - so i don't think, that it's possible.
That's not the idea of ActiveRecord.

If you like to concat values like the example above, you should take DAO
[

[To see links please register here]

][1]
...or if you need ActiveRecord, you should concat the values inside your application

$mailaddress=$model->username.'@'.$model->domain;


[1]:

[To see links please register here]

Reply

#3
add a method to your model, like this:

public function getEmail()
{
return $this->username.'@'.$this->domain;
}

then in views, you can just use the "email" attribute (not getEmail) and you're good to go.
Reply

#4
yes you can do it by using the sql **concat** function in your activerecord definition
...find()
->select(['alias'=>'CONCAT(....)'])
->all();

that would produce a column called alias with the values from the columns used in the concat
hope that still helps
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through