Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
114 views
in Technique[技术] by (71.8m points)

php - How I can insert a value to a model that is type ts_vector?

In my laravel project I have the following table named search_index:

ik    SERIAL PK
name  VARCHAR
value ts_vector

And for this table I have the following model:


namespace AppModel;

use IlluminateDatabaseEloquentModel;

/**
 * @property integer id
 * @property string name
 * @property string value
 */
class SearchIndex extends Model
{

   

}

And I want to insert an new record to the table:

$search_index = new SearchIndex();
$search_index->name  = 'lorem_impsum';
$search_index->value = 'lorem ipsum dolores omea wa mou shindeiru';
$search_index->save();

What I want to do is once I set the value property into SearchIndex to run through to_tsvector() once I save it. In other wotds I want the equivalent query to be:

INSERT INTO search_index(name,value) values ('lorem_impsum', to_tsvector('lorem ipsum dolores omea wa mou shindeiru'));

Do you know how I can do this?

question from:https://stackoverflow.com/questions/65847371/how-i-can-insert-a-value-to-a-model-that-is-type-ts-vector

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...