Search Results

Search found 1021 results on 41 pages for 'has and belongs to many'.

Page 1/41 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Rails model belongs to model that belongs to model but i want to use another name

    - by Micke
    Hello. This may be a stupid question but im just starting to learn Rail thats why i am asking thsi question. I have one model called "User" which handles all the users in my community. Now i want to add a guestbook to every user. So i created a model called "user_guestbook" and inserted this into the new model: belongs_to :user and this into the user model: has_one :user_guestbook, :as => :guestbook The next thing i did was to add a new model to handle the posts inside the guestbook. I named it "guestbook_posts" and added this code into the new model: belongs_to :user_guestbook And this into the user_guestbook model: has_many :guestbook_posts, :as => :posts What i wanted to achive was to be able to fetch all the posts to a certain user by: @user = User.find(1) puts @user.guestbook.posts But it doesnt work for me. I dont know what i am doing wrong and if there is any easier way to do this please tell me so. Just to note, i have created some migrations for it to as follows: create_user_guestbook: t.integer :user_id create_guestbook_posts: t.integer :guestbook_id t.integer :from_user t.string :post Thanks in advance!

    Read the article

  • Rails Model Relationship: Has one but also belongs to many

    - by Lowgain
    I have two Models, Modela and Modelb. Modela can only own one Modelb, but Modelb can be a part of many Modela's. What I have right now is class Modela < ActiveRecord::Base has_one :modelb end class Modelb < ActiveRecord::Base belongs_to :modela, :foreign_key => "modela_id" #might not make sense? end Not too sure about the whole :foreign_key thing I was doing there, but it was where it was when I left off. As I am trying to allow Modelb to be part of many Modela's, I don't want to add a modela_id field to the Modelb table. What is the best way to do this?

    Read the article

  • Rails has-and-belongs-to-many form question

    - by swilliams
    Sorry for the semi-generic title, but I'm still pretty new at rails and couldn't think of a succinct way to put the question. I have a basic habtm model setup: a Project has many Resources and a Resource can have many Projects. I have the database and models setup properly, and can do everything I need to via the console, but I'm having trouble translating it all into the view. On the show view for the Project, I want to be able to create a Resource and automatically assign it to the current Project. Here's my basic html: <p> <b>Name:</b> <%=h @project.name %> </p> <h2>Equipment</h2> <ul> <% @project.resources.each do |r| %> <li><%=h r.name %></li> <% end %> </ul> <h2>Add A Resource</h2> <% form_for(@project) do |f| %> <%= f.error_messages %> <p> Resource Name:<br /> <%= f.text_field :resources %> </p> <p> <%= f.submit 'Create' %> </p> <% end %> Obviously, that form won't work, but I'm at a loss for what to do next. I've searched around for various examples, but haven't found one for what I'm trying to do here. One thing I've thought of was to change the form to be form_for(Resource.new) and include a hidden input of the @project.id. And then when the resource_controller handles the form, check for that id and go from there. That seems like an ugly kludge though.

    Read the article

  • The report belongs to a package that is not installed

    - by user71700
    I have gotten the error message "The report belongs to a package that is not installed." Generally I would just ignore that since seemingly there is no problem except I got a crash report and then I said to report the problem and then I get this. Now, how can a package or program crash that is not even installed? Sounds a little paradox, isn't it? What should I do with this? Why does this even come up?

    Read the article

  • Exclude category from Wordpress home page unless it belongs to another category

    - by sirlancelot
    I have multiple users adding content to restricted categories (using RoleScoper) in my Wordpress setup that don't show up on the homepage (custom template with query_posts()). I'm looking for a way to "promote" the submitted content to the homepage by adding it to another category. My loop code looks like this: <?php query_posts($query_string . '&cat=-37'); if (have_posts()): while (have_posts()): the_post(); ?> This will exclude all posts in category 37. However, even if I add the post to a different category it still gets excluded. Is there a way to exclude a post if it belongs to just that one category?

    Read the article

  • Dependency injection: what belongs in the constructor?

    - by Adam Backstrom
    I'm evaluating my current PHP practices in an effort to write more testable code. Generally speaking, I'm fishing for opinions on what types of actions belong in the constructor. Should I limit things to dependency injection? If I do have some data to populate, should that happen via a factory rather than as constructor arguments? (Here, I'm thinking about my User class that takes a user ID and populates user data from the database during construction, which obviously needs to change in some way.) I've heard it said that "initialization" methods are bad, but I'm sure that depends on what exactly is being done during initialization. At the risk of getting too specific, I'll also piggyback a more detailed example onto my question. For a previous project, I built a FormField class (which handled field value setting, validation, and output as HTML) and a Model class to contain these fields and do a bit of magic to ease working with fields. FormField had some prebuilt subclasses, e.g. FormText (<input type="text">) and FormSelect (<select>). Model would be subclassed so that a specific implementation (say, a Widget) had its own fields, such as a name and date of manufacture: class Widget extends Model { public function __construct( $data = null ) { $this->name = new FormField('length=20&label=Name:'); $this->manufactured = new FormDate; parent::__construct( $data ); // set above fields using incoming array } } Now, this does violate some rules that I have read, such as "avoid new in the constructor," but to my eyes this does not seem untestable. These are properties of the object, not some black box data generator reading from an external source. Unit tests would progressively build up to any test of Widget-specific functionality, so I could be confident that the underlying FormFields were working correctly during the Widget test. In theory I could provide the Model with a FieldFactory() which could supply custom field objects, but I don't believe I would gain anything from this approach. Is this a poor assumption?

    Read the article

  • Netbeans - *Easy* way to tell which Netbeans project a file belongs to

    - by sdek
    I was wondering if there is a way in Netbeans (v 6.8, or whatever) to have the editor tabs colored based on which project the file belongs to? Or some other easy way to distinguish which project a file belongs to. Basically my problem is that I have 3-4 netbeans projects, which all have a very similar code base (production version, staging version, development version 1, development version 2), and sometimes I have files open from a few different projects, and I get confused as to which project the file belongs to. And I know that you can hover over the tab and you can see which project it belongs to, but it would be fantastic if there was another, easier way to visually distinguish which project a file belongs to.

    Read the article

  • Let a question always :include its author, how?

    - by Freewind
    class Question < ActiveRecord::Base belongs_to :author end class Author < ActiveRecord::Base has_many :questions end When I find some questions, I usually need to get their authors at the same time, so I use: Question.find(:all, :include=>:authors) But I don't write the ":include" part everywhere. I hope I can define the "include" somewhere only once, and when I find questions, the author will be automaticly loaded. Is there any way to do this?

    Read the article

  • PHP/MySQL: Check if something 'belongs-to' something else?

    - by Nebs
    I have two tables: Stores and Items. The relationship is: Stores 1---* Items In PHP/MySQL what would be the best (fastest/simplest) way to check if a particular item belongs to a particular store. In other words given for example: $store_id = 1; $item_id = 12; I want to check if item 12 belongs to store 1 (and not some other store). I usually do a select on Items matching both the store_id and item_id and limit the results to 1. Then check how many rows (0 or 1) were returned with mysql_num_rows. Is there a better way? Update: Both tables have an "id" column. The Items table has a "store_id" column.

    Read the article

  • Validate a belongs to association in a build situation.

    - by Victor Martins
    I have a Mission model that has_many Task, and the Task belongs_to Mission For security I've made this validation on the Task Model: validates_presence_of :mission_id validates_numericality_of :mission_id But the problem is that when create a Mission and add tasks like this: @mission.tasks.build The validation returns error, because the mission id on the task is null ( the mission wasn't yet created ) If I delete the validation, the Mission and Task is created successfuly, but how can I keep the validation and still have this work? I could do a callback after the save, but I don't think that's right, because I don't want to save Tasks without a mission_id. P.S. I'm hidding my mission field on the form. If I have it visible, it will show the currect mission and everything is ok. But if I hidde it the error happens. <%= f.hidden_field :mission, :label => "Missão" %> Is the form reseting the attributes given by the controller on the new action?

    Read the article

  • Remote access to phpmyadmin from computer belongs to same LAN

    - by Charles
    OK... I solved it. It is because I have not configured the httpd.conf to allow the centos listen port 80 and 8080. Listen 80 Listen 8080 I have setup the myphpadmin on my CentOS 6.4 recently. I can access and login to the myphpadmin on my localhost. However, when I type http://[hostipaddr]/phpmyadmin on my other computer in the same LAN with the CentOS, the browser simply cannot access the page. Below are some of the current configuration. Anyone can help please......? config.inc.php $i++; /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'http'; /* Server parameters */ $cfg['Servers'][$i]['host'] = 'localhost'; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; /* Select mysql if your server does not have mysqli */ $cfg['Servers'][$i]['extension'] = 'mysql'; $cfg['Servers'][$i]['AllowNoPassword'] = false; phpmyadmin.conf <Directory /var/www/html/phpmyadmin/> order allow,deny allow from all </Directory> Furthermore, I can access the webpage that stored in the CentOS from my other computer without problems. After using wireshark and tcpdump, I found that the server (the Cent OS) keep resetting the connection. (192.168.1.106 is my other computer, 192.168.1.101 is my CentOS) 23:29:42.281473 IP 192.168.1.106.55999 > 192.168.1.101.webcache: Flags [S], seq 2559409090, win 65535, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0 23:29:42.281504 IP 192.168.1.101.webcache > 192.168.1.106.55999: Flags [R.], seq 0, ack 2559409091, win 0, length 0 I have disabled the iptables service on the CentOS already.

    Read the article

  • count number of business that belongs to subcategory in doctrine

    - by Ibrahim Azhar Armar
    this is follow up of this question. count number of foreign keys i am using doctrine 1.2 and i want to count the number of business that belongs to subcategory. following are the mysql tables. 1.fi_category +----+-----------------+-----------------+ | id | name | slug | +----+-----------------+-----------------+ 2.fi_subcategory +----+-----------------+-----------------+-------------+ | id | name | slug | category_id | +----+-----------------+-----------------+-------------+ 3.fi_business_subcategory +----+-------------+----------------+ | id | business_id | subcategory_id | +----+-------------+----------------+ i am using this DQL. $q = Doctrine_Query::create() ->select('c.name, c.slug, sc.name, sc.slug') ->from('Model_Category c') ->leftJoin('c.Subcategory sc') ->leftJoin('sc.BusinessSubcategory bsc'); which gives me something like this. Array ( [0] => Array ( [id] => 1 [name] => Entertainment & Lifestyle [slug] => entertainment-lifestyle [Subcategory] => Array ( [0] => Array ( [id] => 1 [name] => Arts and Crafts [slug] => arts-and-crafts ) [1] => Array ( [id] => 2 [name] => Family [slug] => family ) [2] => Array ( [id] => 3 [name] => Fashion [slug] => fashion ) ) ) ) i am looking to fetch the number of business, i.e the returned result should be something like this depending on the business it belongs. Array ( [0] => Array ( [id] => 1 [name] => Entertainment & Lifestyle [slug] => entertainment-lifestyle [Subcategory] => Array ( [0] => Array ( [id] => 1 [name] => Arts and Crafts [slug] => arts-and-crafts [business_count] => 35 ) [1] => Array ( [id] => 2 [name] => Family [slug] => family [business_count] => 10 ) [2] => Array ( [id] => 3 [name] => Fashion [slug] => fashion [business_count] => 27 ) ) ) ) tried various ways using DQL, but nothing seems to work out. any idea how should i go with what i want?

    Read the article

  • mysql joins - how to find all children that belongs to ALL parents

    - by kimsia
    I have three mysql tables items the columns are id, title items_in_categories the columns are id, item_id, category_id categories the columns are id, title I want to find all the items that belong to ALL the stated categories. Not any one category, but ALL categories Eg, if I want to search all the items that belongs to category id 3 and 5 I would like to use as simple a way as possible. I have tried AND and a nested NOT EXISTS as stated in the mysql manual. Nothing worked.

    Read the article

  • Proving that a function f(n) belongs to a Big-Theta(g(n))

    - by PLS
    Its a exercise that ask to indicate the class Big-Theta(g(n)) the functions belongs to and to prove the assertion. In this case f(n) = (n^2+1)^10 By definition f(n) E Big-Theta(g(n)) <= c1*g(n) < f(n) < c2*g(n), where c1 and c2 are two constants. I know that for this specific f(n) the Big-Theta is g(n^20) but I don't know who to prove it properly. I guess I need to manipulate this inequality but I don't know how

    Read the article

  • Display ALL categories that a product belongs to in Magento

    - by Jason
    I am conceptualizing a new Magento site which will have products that are included in several categories. What I am wondering is if I can display all categories a product is in on the product detail page. I know that it is possible to get the category, but is it possible to display a list of all categories which a product belongs to? For example, a shirt may be included in the Shirts category, as well as in Designers and Summer. Ideally, I would like to be able to display the following: More from:    Men Shirts    Men Designers Barnabé Hardy    Men Summer

    Read the article

  • Foreign Key Relationships and "belongs to many"

    - by jan
    I have the following model: S belongs to T T has many S A,B,C,D,E (etc) have 1 T each, so the T should belong to each of A,B,C,D,E (etc) At first I set up my foreign keys so that in A, fk_a_t would be the foreign key on A.t to T(id), in B it'd be fk_b_t, etc. Everything looks fine in my UML (using MySQLWorkBench), but generating the yii models results in it thinking that T has many A,B,C,D (etc) which to me is the reverse. It sounds to me like either I need to have A_T, B_T, C_T (etc) tables, but this would be a pain as there are a lot of tables that have this relationship. I've also googled that the better way to do this would be some sort of behavior, such that A,B,C,D (etc) can behave as a T, but I'm not clear on exactly how to do this (I will continue to google more on this) What do you think is the better solution? UML: Here's the DDL (auto generated). Just pretend that there is more than 3 tables referencing T. -- ----------------------------------------------------- -- Table `mydb`.`T` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`T` ( `id` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY (`id`) ) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`S` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`S` ( `id` INT NOT NULL AUTO_INCREMENT , `thing` VARCHAR(45) NULL , `t` INT NOT NULL , PRIMARY KEY (`id`) , INDEX `fk_S_T` (`id` ASC) , CONSTRAINT `fk_S_T` FOREIGN KEY (`id` ) REFERENCES `mydb`.`T` (`id` ) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`A` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`A` ( `id` INT NOT NULL AUTO_INCREMENT , `T` INT NOT NULL , `stuff` VARCHAR(45) NULL , `bar` VARCHAR(45) NULL , `foo` VARCHAR(45) NULL , PRIMARY KEY (`id`) , INDEX `fk_A_T` (`T` ASC) , CONSTRAINT `fk_A_T` FOREIGN KEY (`T` ) REFERENCES `mydb`.`T` (`id` ) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`B` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`B` ( `id` INT NOT NULL AUTO_INCREMENT , `T` INT NOT NULL , `stuff2` VARCHAR(45) NULL , `foobar` VARCHAR(45) NULL , `other` VARCHAR(45) NULL , PRIMARY KEY (`id`) , INDEX `fk_A_T` (`T` ASC) , CONSTRAINT `fk_A_T` FOREIGN KEY (`T` ) REFERENCES `mydb`.`T` (`id` ) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`C` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`C` ( `id` INT NOT NULL AUTO_INCREMENT , `T` INT NOT NULL , `stuff3` VARCHAR(45) NULL , `foobar2` VARCHAR(45) NULL , `other4` VARCHAR(45) NULL , PRIMARY KEY (`id`) , INDEX `fk_A_T` (`T` ASC) , CONSTRAINT `fk_A_T` FOREIGN KEY (`T` ) REFERENCES `mydb`.`T` (`id` ) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB;

    Read the article

  • Finding the FORM that an element belongs to in JavaScript

    - by Magnus Smith
    How can I find out which FORM an HTML element is contained within, using a simple/small bit of JavaScript? In the example below, if I have already got hold of the SPAN called 'message', how can I easily get to the FORM element? <form name="whatever"> <div> <span id="message"></span> </div> </form> The SPAN might be nested within other tables or DIVs, but it seems too long-winded to iterate around .parentElement and work my way up the tree. Is there a simpler and shorter way? If it wasn't a SPAN, but an INPUT element, would that be easier? Do they have a property which points back to the containing FORM? Google says no...

    Read the article

  • Rails help looping trough has one and belongs to association

    - by Rails beginner
    This is my kategori controller show action: def show @kategori = Kategori.find(params[:id]) @konkurrancer = @kategori.konkurrancer respond_to do |format| format.html # show.html.erb format.xml { render :xml => @kategori } end end This is kategori view show file: <% @konkurrancer.each do |vind| %> <td><%= vind.name %></td> <td>4 ud af 5</td> <td><%= number_to_currency(vind.vaerdi, :unit => "DKK", :separator => ".", :delimiter => ".", :format => "%n %u", :precision => 0) %></td> <td>2 min</td> <td>Nyhedsbrev</td> <td><%= vind.udtraekkes.strftime("%d %B") %></td> </tr> <% end %> My kategori model: class Kategori < ActiveRecord::Base has_one :konkurrancer end My konkurrancer model: class Konkurrancer < ActiveRecord::Base belongs_to :kategori end I want show all of the konkurrancer that have an association to the kategori model With my code I get the following error: NoMethodError in Kategoris#show Showing C:/Rails/konkurranceportalen/app/views/kategoris/show.html.erb where line #12 raised: undefined method `each' for "#":Konkurrancer

    Read the article

  • What Belongs to the Aggregate Root

    - by jlembke
    This is a practical Domain Driven Design question: Conceptually, I think I get Aggregate roots until I go to define one. I have an Employee entity, which has surfaced as an Aggregate root. In the Business, some employees can have work-related Violations logged against them: Employee-----*Violations Since not all Employees are subject to this, I would think that Violations would not be a part of the Employee Aggregate, correct? So when I want to work with Employees and their related violations, is this two separate Repository interactions by some Service? Lastly, when I add a Violation, is that method on the Employee Entity? Thanks for the help!

    Read the article

  • How create a fullscreen view of a group of controls, that belongs to a tabpage

    - by voodoomsr
    Hi all, i would like to know what is the correct way to create a fullscreen view of a tabpage control. This page has other controls, and that controls has various events that are subscribed. I was trying creating a new fullscreen form and copy all controls of the tabs to that form, but with this approach i need to resubscribe every control to the corresponding handler. If i only add the references the subscription remains but when the fullscreen form is close also the referenced copied controls are lost.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >