How to get objects from the “many” table record?
I have list of rsObjectComments and I need to fetch rsObjects.
For example:
schema.yml:
rsObject:
actAs:
Timestampable: ~
Sluggable:
fields: [name]
columns:
name: { type: string(255), notnull: true, unique: true }
description: { type: string(6000), notnull: true }
relations:
rsObjectComments:
class: rsObjectComments
local: id
foreign: rsobject_id
type: many
foreignAlias: Comments
rsObjectComments:
actAs:
Timestampable: ~
columns:
rsobject_id: { type: integer, notnull: true }
fromname: { type: string(100), notnull:true }
fromemail: { type: string(100), notnull:true }
comments: { type: string(1000), notnull:true }
is_public: { type: boolean, notnull: true, default: 1 }
relations:
rsObject: { onDelete: CASCADE, local: rsobject_id, foreign: id, foreignAlias: rsObjectCommentsAlias }
I encourage you to read the whole documentation page called: Inside The Model Layer (Doctrine) (specially the part Retrieving Related Record).
You will see a basic example of article with many comments (which is almost the same as yours).
For your example, if you have a
rsObjectyou can fetch relatedrsObjectCommentsusing:I’m using
getCommentsbecause you defined theforeignAliaswithComments.And if you want to work on them
And in the reverse order, if you have a comment and want to retrieve its article.