I'm creating social network site and И have wall where user post will be fetched. When user create new post they have options to attach photos. Post and attachment have diferent database tables and diferent Controllers and Models.
Problem is when i execute query for insert new post И need one more query for attachment witch will hold post_id. So first I need insert post in database then И need to insert attachments for that post? But how to get id for that post when all query is executed in some time?
Lets see my tables:
Post
post_id account_id post_text
------- ---------- -----------------------
1 1 Hello world post
Attachments
attachment_id post_id attachment_type attachment_name
------------- ------- --------------- -----------------
1 1 3 photo_1.jpg
2 1 2 video_1.mp4
3 1 3 photo_2.jpg
I dont want use transactions for this.
On submit I need to insert :
INSERT INTO post bla bla bla
INSERT INTO attachments bla bla bla <post_id> //how to get it when is executed in some time?