This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

planetadeleste
planetadeleste

Hello, I'm stuck trying to make a belongsToMany relation . I have the models Property and Attribute; and the Controller Properties.

The Properties Controller have this settings.

public $implement = [
    'Backend.Behaviors.FormController',
    'Backend.Behaviors.ListController',
    'Backend.Behaviors.RelationController',
];
public $relationConfig = 'config_relation.yaml';

The file config_relation.yaml

attributes:
    label: Attributes
    list: @/plugins/pronet/realestate/models/attribute/columns_relation.yaml

The file columns_relation.yaml

# ===================================
#  List Column Definitions
# ===================================
columns:
    name:
        label: pronet.realestate::lang.global.label.name
        searchable: yes
    slug:
        label: pronet.realestate::lang.global.label.slug
        searchable: yes
    in_search:
        label: pronet.realestate::lang.global.label.in_search
        searchable: false
        type: switch

In Controller partial properties/update.htm

<?= $this->relationRender('attributes'); ?>

In Property Model

public $belongsToMany = [
    'attributes' => ['Pronet\RealEstate\Models\Attribute', 'table' => 'pronet_realestate_property_attributes', 'primaryKey' => 'property_id', 'foreignKey' => 'attribute_id'],
 ];

I don't know what i'm missing, but when a click the button to add a new attribute, receive this message:

"SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'field list' (SQL: select `` from `pronet_realestate_attributes` inner join   `pronet_realestate_property_attributes` on `pronet_realestate_attributes`.`id` = `pronet_realestate_property_attributes`.`attribute_id` where `pronet_realestate_attributes`.`deleted_at` is null and `pronet_realestate_property_attributes`.`property_id` = 1)" 

Any help will be appreciate. Thanks and sorry my english

axomat
axomat

I presume name, slug and in-search exist as fields in your attributes table?

These sort of problems are really difficult to diagnose because the form is ajax based. I would really like one of the helpers like Clockwork to be baked into October. I have tried to install them but because of the automatic updates of October (which works brilliantly by the way) instead of using composer that is not a great solution.

planetadeleste
planetadeleste

Thanks for your reply @axomat. I resolve the attributes relation making it manually, extending the Form Widget.

But now i found the some problem with another relation tables.
I'm writing a real estate plugin.And I have the models Property (like houses, condos, etc.), Transactions (like sale, rent, project, etc) , PriceType (like hi season, low season, January, etc), Currency (like dollar, euro, etc).

Them I have the relation $belongsToMany in Property model.

public $belongsToMany = [
  'transactions' => [
    'Pronet\RealEstate\Models\Transaction',
    'table' => 'pronet_realestate_property_transactions',
    'primaryKey' => 'property_id',
    'foreignKey' => 'transaction_id',
    'pivot' => ['value', 'price_type_id', 'currency_id'],
  ],
];

In Properties Controller

public $relationConfig = 'config_relation.yaml';

In config_relation.yaml

transactions:
    label: pronet.realestate::lang.properties.label.transactions
    list: @/plugins/pronet/realestate/models/transaction/columns.yaml
    emptyMessage: pronet.realestate::lang.properties.label.no_transactions
    defaultSort: name
    showSorting: false
    pivot:
      fields:
        value:
          label: pronet.realestate::lang.global.label.value
          type: text
        price_type_id:
          label: pronet.realestate::lang.global.label.price
          type: dropdown
          options: listPriceTypes
        currency_id:
          label: pronet.realestate::lang.global.label.currency
          type: dropdown
          options: listCurrencies 

In property/fields.yaml

# TAB TRANSACTIONS
    transactions:
      tab: pronet.realestate::lang.properties.label.transactions
      context: update
      type: partial
      path: @/plugins/pronet/realestate/controllers/properties/_form_transactions.htm

In _form_transactions.htm partial

<?= $this->relationRender('transactions'); ?>

The tab Transactions are rendered ok, like the next image:

OC

But, when I click to add a new Transaction, I have this message:

OC

Already been a week trying to solve this problem, but can not find any solution, using the CMS itself to generate the form of relationships.

Any help will be appreciated

Many thanks.

Last updated

kris2481
kris2481

I also ran into the same issue. to fix the model add the following to your config_relations.yaml

form: @/plugins/dma/friends/models/step/fields.yaml

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.