Results 1 to 2 of 2

Thread: How to request with hasMany relation ?

  1. #1
    New user
    Join Date
    09-08-15.
    Posts
    2

    Frage How to request with hasMany relation ?

    I created an extension with a relation hasMany, we had modifications on tl_news.php file.

    tl_news.php

    PHP Code:
    'restaurants' => array
            (
                
    'label'                   => &$GLOBALS['TL_LANG']['tl_news']['restaurants'],
                
    'exclude'                 => true,
                
    'filter'                  => true,
                
    'inputType'               => 'select',
                
    'foreignKey'              => 'tl_restaurants.title',
                
    'eval'                    => array('tl_class'=>'w50''multiple'=>true),
                
    'relation'                => array('type'=>'hasMany''load'=>'eager'),
                
    'sql'                     => "varchar(255) NULL"
            
    ), 
    Now I want to get all the news by the id of a restaurant.

    Is there a function to search on this field like findBy... ?

    thank you,

  2. #2
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    Why not use
    PHP Code:
    \NewsModel::findByRestaurant('restaurant name'); 
    Maybe this will help https://docs.contao.org/books/cookbook/de/Models.html. Sorry, not yet translated.
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •