I have bellow raw mysql query, what i want to do is to change this to query builder. need help.
SET @groupIds = '11,14';
SET @eventIds = '13,5';
SET @friendIds = '1000022';
SET @userFollowings = '1000001';
SELECT sn_posts.*
FROM sn_posts
WHERE
sn_posts.deleted_at is null AND
(
sn_posts.user_id = '1000042' OR (
(
IF(@groupIds is not null AND @groupIds <> '',FIND_IN_SET(sn_posts.postable_id,@groupIds),0)
OR IF(@eventIds is not null AND @eventIds <> '',FIND_IN_SET(sn_posts.postable_id,@eventIds),0)
OR IF(sn_posts.privacy_level = 0, (
IF(@friendIds is not null AND @friendIds <> '', FIND_IN_SET(sn_posts.`user_id`,@friendIds),0)
OR IF(@userFollowings is not null AND @userFollowings <> '',FIND_IN_SET(sn_posts.`user_id`,@userFollowings),0)
),
IF(@friendIds is not null AND @friendIds <> '', FIND_IN_SET(sn_posts.user_id,@friendIds),0)
)
)
AND IF(sn_posts.`parent_id` IS NOT NULL,(
SELECT parent.id FROM sn_posts AS parent
WHERE parent.id = sn_posts.`parent_id` AND IF(parent.privacy_level = 0,1,IF(@friendIds is not null AND @friendIds <> '', FIND_IN_SET(parent.`user_id`,@friendIds),0))
),1)
)
)
ORDER BY sn_posts.created_at desc
LIMIT 21,10
I have php variables instead of those mysql variables. Because of need for result as collection, i need a way to get the result as collection.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire