I have an author_id array. I want to fetch authors by IDs using relationship. I already fetched editions and publishers but the author has an array.
----------------------------------------------------------------------
| id | title | author_id | edition_id | publisher_id |
|----|------------------|----------------|------------|--------------|
| 2 | Web Development | ["1","3","4"] | 2 | 1 |
|----|------------------|----------------|------------|--------------|
Please check image:-
Please provide suggestions how can I get array column field in relationship
You should use a pivot table and a many-to-many relation to create this link correctly.
The new table would contain the author_id
and the local_id
. This way, a local row can have multiple authors and the relation can be defined in your database.
You need to use for loop to fetch authors by using ID
Like You have an array author_id = [1, 3, 4]
so you need to loop it base on the count of the author_id array
for(i=0; i<= count(author_id); i++){
//your condition based on the index of for loop
select author from sometable where author_id[$i] = author
}