Undefined using aldeed:tabular and reywood:publish_composite

I am trying to follow aldeed’s example here for using reywood:publish_composite. I can see all of the building names in my table, but I can’t see the region names. Can anyone see what I’m doing wrong here?

{{> tabular table=TabularTables.Buildings class="table table-striped"}}

an example of a Building (in the Buildings collection):

  _id: 'XDkCcn9RrSx7YjKha',
  name: 'My Building #1',
  region_id: 'RfcrxrD7W7MnQvqiM'

an example of a Region (in the Regions collection):

  _id: 'RfcrxrD7W7MnQvqiM',
  name: 'Southern California'

in common/helpers.js

  region_name: function() {
    var region = Regions.findOne({_id: this.region_id});
    return region && region.name;

in common/tables.js

TabularTables = {};
TabularTables.Buildings = new Tabular.Table({
  name: "Buildings",
  collection: Buildings,
  pub: 'tabularBuildings',
  allow: function() {
    return true;
  order: [[0, "asc"]],
  columns: [
    {data: "name", title: "Building Name"},
    {data: 'region_name()', title: "Region"}

In server/publish.js

Meteor.publishComposite("tabularBuildings", function(tableName, ids, fields) {
  check(tableName, String);
  check(ids, Array);
  check(fields, Match.Optional(Object));
  return {
    find: function() {
      return Buildings.find({_id: {$in: ids}}, {fields: fields});
    children: [
      find: function(building) {
        return Regions.find({_id: building.region_id}, {limit: 1, fields: {name: 1}, sort: {_id: 1}});

I’m also using meteorhacks:flow-router, meteorhacks:flow-layout, arillo:flow-router-helpers

That seems odd to me. That will return a boolean, no?

I think you are correct (even though aldeed did, in fact, write it that way).

If I change it to be

return region.name

I get an error saying region is undefined.

It says in the aldeed:tabular documentation that the subscriptions are handled. Do I need to explicitly subscribe the Regions collection somewhere?

I’m not sure. I’ve used both packages before at one time or another but not both together that i can recall.

It’s a bit hard to tell by reading the code what the issue might be. If you could create a repro I’d be happy to debug it for you.

Here is the GitHub repo.

You need to run it like this

meteor --settings settings.dev.json

You can login with user admin@some.com and pass 12345. The /buildings route is the one I’m trying to master.

1 Like

Cheers, I’ll fork it if that’s okay so if I have to change the code I can push it back to github.

That’s great @peter.roehlen. Thank yo for the help.

I have just noticed that if I create a region ID column like this

{data: 'region_id', title: "Region ID"},

the region name show up in the table. It appears that region_id is not subscribed. Maybe I need to do this and then hide the Region ID column.

In any event, I hope you can see something more elegant.

Yeah that’s exactly what I had to do to make it work. I can’t see that that’s documented anywhere unfortunately so it might be a bug that you have to do that.


No disrepect to Aldeed but some of these smart / dynamic packages can get to a point sometimes where it’s easier just to code a custom solution. Otherwise, everything ends up being abstracted away to so many levels and you end up coding with data which is harder to read/follow and impossible to know sometimes where the issue is when something goes wrong. Maybe the tradeoff is worth if it if you are cutting out dozens of tables. /my 2 cents.

Actually, I think this is how you are supposed to do it:


Use the ‘extraFields’ option instead of a hidden column. Works when I tried it.

It’s documented here:

Note that for this to work properly, you must ensure that the firstName and lastName fields are published. If they’re included as the data for other columns, then there is no problem. If not, you can use the extraFields option or your own custom publish function.

1 Like

That seems less hackish (although not documented). Good fix @peter.roehlen. I also added the _id field. It wasn’t coming through either.

Yeah sorry, I edited my post with where it’s documented. Just wasn’t documented in the exact example you were following unfortunately but elsewhere.