vincent15000's avatar

Passing only an ID vs passing the entire object

Hello,

I have this database :

  • tables
  • articles : table_id
  • groups : table_id
  • variables : group_id
  • article_group : article_id, group_id, pivot datas

I have to display on the same page the articles, the groups, the variables for each group and the articles with the pivot datas for each group.

In the TablePage Livewire component, I load the table and its relationships as a computed property.

I have created several child components : groups component, group component, variables component, variable component, articles component and article component.

If I trigger an action from a child component, I loose the pivot datas.

What can I do to avoid this ?

I have tried to pass only the IDs to the child components, but this way I have a big number of queries done to the database.

Thanks ;).

V

0 likes
3 replies
valentin_vranic's avatar

Firstly the issue title and your real question I think is a bit misleading, thus I don't see the real relation between them (at first look).

IMO I would pass the object if it't not so heavy, and a simple model, and use #[Locked] on it in child, to prevent any malicious data manipulation between queries. And as a mandatory step, when looping the over parent property of child components, passing the :key on it to keep track of them.

IDK what the pivot datas consists and what losing them actually means. That's correct that the action is isolated for a component. But I'm not sure that refreshing the parent makes it efficient.

Providing some essential code would help a lot.

1 like

Please or to participate in this conversation.