S
S
Sergey Beloventsev2016-05-11 23:02:31
Yii
Sergey Beloventsev, 2016-05-11 23:02:31

How to make query with mySQL date formation?

there is a request

SELECT name_film, date( from_unixtime( created_at ) ) created_at
    FROM `fl_films`
    ORDER BY created_at

can it be done in ActiveRecord yii2 ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
matperez, 2016-05-12
@Sergalas

1. make a regular model for fl_films
2. create a class like FilmsQuery extends ActiveQuery and throw it into the init method

$this->select([
  '*',
  'date( from_unixtime( created_at ) ) created_at'
]);

3. In the model, override the find method
I think it's a bad idea to override the contents of an existing field. Better get a new one, or do the transformation directly in the model: return the date in the required format in some FilmModel::getCreationDate().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question