Using Codeigniter and Datamapper: I have 2 tables: tags and clients. Clients can have many tags, tags can have many clients. I am using a separate join table to save the relationships.
I have a page for managing an individual tag, where I am iterating through every client, and want to check if each one is related to this tag.
The ???? in the code below determines if the checkbox is checked, it should be TRUE if the client has the tag, FALSE if not.
<h2>Manage Tag: <?php echo $tag->name; ?></h2>
<?php foreach ($clients as $client): ?>
<label>
<?php echo form_checkbox('client_id[]', $client->id, ????); ?>
<?php echo $client->name; ?>
</label>
<?php endforeach; ?>
How can I check if $client is related to $tag in this loop with Datamapper?
How about
or
See http://datamapper.wanwizard.eu/pages/count.html#is_related_to
Note that this will fire additional count() queries, you might be better of fetching $tag->clients, and then check in your loop if