dboehmer / coocook

👨‍🍳🦉 Web application for collecting recipes and making food plans
https://coocook.org/
Other
11 stars 2 forks source link

Replace Component::ResultsetRelationships with $rs->search_related #57

Closed dboehmer closed 6 years ago

dboehmer commented 6 years ago

I spoke DBIC developer ribasushi at 34th Chaos Communication Congress (34c3) in Leipzig. (Greetings from there!) What I didn't know is that DBIC in fact has resultset relationships.

Problem is there is no accessor for them because it would be so many subs. Instead you can call

$related_resultset = $src_resultset->search_related( my_related_objects => ... );

Bonus: To optimize by replacing the current resultset with a complex WHERE-clause by a simple WHERE id IN (...) we can reuse this code to automatically get the identifying columns (e.g. PK columns or UNIQUE CONSTRAINT columns): https://metacpan.org/source/RIBASUSHI/DBIx-Class-0.082840/lib/DBIx/Class/ResultSet.pm#L1962-2013