has_one_or_many.php 854 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php namespace Laravel\Database\Eloquent\Relationships;
  2. use Laravel\Database\Eloquent\Model;
  3. class Has_One_Or_Many extends Relationship {
  4. /**
  5. * Insert a new record for the association.
  6. *
  7. * @param array $attributes
  8. * @return bool
  9. */
  10. public function insert($attributes)
  11. {
  12. $attributes[$this->foreign_key()] = $this->base->get_key();
  13. return parent::insert($attributes);
  14. }
  15. /**
  16. * Set the proper constraints on the relationship table.
  17. *
  18. * @return void
  19. */
  20. protected function constrain()
  21. {
  22. $this->table->where($this->foreign_key(), '=', $this->base->get_key());
  23. }
  24. /**
  25. * Set the proper constraints on the relationship table for an eager load.
  26. *
  27. * @param array $results
  28. * @return void
  29. */
  30. public function eagerly_constrain($results)
  31. {
  32. $this->table->where_in($this->foreign_key(), array_keys($results));
  33. }
  34. }