$input="(name eq \"xxxx\" and user:(post.id eq 6 and post.post eq \"testing\") and data eq \"Hello World!\")";
$inarr = [":(", ")","("];
$reparr = [" and ", "", ""];
$input=str_replace($inarr, $reparr, $input);
$resultarr = explode(" and ", $input);
echo '[
[
$resultarr[0]' . ',' .
'"' . $resultarr[1] . '" => [' .
$resultarr[2] . ',' .
$resultarr[3] . ',' .
'],
"' . $resultarr[4] . '",
],
[
"name",
"user" => [
post.id,
post.post
],
"data",
],
]';
基本上在上面的代码片段中,我试图将属性仅限于书籍class UserSerializer < ActiveModel::Serializer
attributes :id, :name
has_many :books, each_serializer: SimpleBookSerializer
end
class BookSerializer < ActiveModel::Serializer
# lots of attributes, associations
end
class SimpleBookSerializer < ActiveModel::Serializer
attributes :id, :title
end
,所以我写了一个简单的序列化程序,它只返回id,title。但是调用了默认的书籍序列化程序,我得到了我不需要的所有数据。如何防止这种